在我的基于Spring 3.1的应用程序中,@ManagedAttributes和@ManagedOperations都没有被捕获或记录。
因此,我通过对MBeanExporter进行扩展来解决这个问题,当MBean方法调用失败时,它将失败。
public class LoggingFailedCallsMBeanExporter extends MBeanExporter {
protected ModelMBean createModelMBean() throws MBeanException {
ModelMBean superModelMBean = super.createModelMBean();
if (superModelMBean instanceof SpringModelMBean) {
return new SpringModelMBean() {
@Override
public Object invoke(String opName, Object[] opArgs, String[] sig) throws MBeanException, ReflectionException {
try {
return super.invoke(opName, opArgs, sig);
} catch (MBeanException e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
} catch (ReflectionException e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
} catch (RuntimeException e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
} catch (Error e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
}
}
};
} else {
return new RequiredModelMBean() {
@Override
public Object invoke(String opName, Object[] opArgs, String[] sig) throws MBeanException, ReflectionException {
try {
return super.invoke(opName, opArgs, sig);
} catch (MBeanException e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
} catch (ReflectionException e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
} catch (RuntimeException e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
} catch (Error e) {
LOGGER.warn("Issue on a remote call", e);
throw e;
}
}
};
}
}