当数据库发生更改时,我正在使用 spring boot jmx 远程执行该方法。每件事都运行良好,当我使用原始数据类型作为返回值时,我可以在 Windows 中使用 jmc.exe 监控我的应用程序。现在我需要返回对象(不是原始数据类型,而是一个类)值作为我的方法的返回值。实际上,这个对象与我的班级在同一个包中。但是当我使用 jmx 远程运行该方法时,我得到了
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.ff.KeyValue (no security manager: RMI class loader disabled).
我的代码如下
@Service
@ManagedResource(description = "JMX managed resource for updating map when database is updated",
objectName = "chargeCode:name=ChargeCodeService")
public class ChargeCodeService {
private static final Logger logger = LoggerFactory.getLogger(ChargeCodeService.class);
private final ChargeCodeRepository chargeCodeRepository;
private Map<String, KeyValue<String,String>> chargeCodeMap = new HashMap<>();
@Autowired
public ChargeCodeService(ChargeCodeRepository chargeCodeRepository) {
this.chargeCodeRepository = chargeCodeRepository;
}
@PostConstruct
@ManagedOperation
public Map<String, KeyValue<String,String>> chargeCodMapInitial() {
logger.info("ready to read chargeCode data from database. this operation will do when an update occure in database");
List<ChargeCode> chargeCodes = chargeCodeRepository.findAll();
for (ChargeCode chargeCode : chargeCodes) {
chargeCodeMap.put(chargeCode.getIacChargeCode(),new KeyValue<>( chargeCode.getBankChargeCode(),chargeCode.getTopupProvider()));
}
return chargeCodeMap;
}
@ManagedAttribute
public Map<String, KeyValue<String, String>> getChargeCodeMap() {
return chargeCodeMap;
}
}
KeyValue
课程如下:
public class KeyValue<K, V> implements Map.Entry<K, V>, Serializable {
private static final long serialVersionUID = -2610138893852455839L;
private K key;
private V value;
public KeyValue() {
}
public KeyValue(K key, V value)
{
this.key = key;
this.value = value;
}
getter,setter;
}