I am using spring boot jmx to remotely execute the method when a change happen in database. Every thing works well and I could monitor my app using jmc.exe in windows when I use primitive data type as return value . Now I need to return Object(not primitive data type but a class) value as return of my method. Actually this object is in the same package that my class is. but when I run the method remotely using jmx I get
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.ff.KeyValue (no security manager: RMI class loader disabled).
my code is as below
@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;
}
}
and the KeyValue
class is as below:
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;
}