我需要在30种不同的类中向JMX公开大约60种操作.用DynamicMBean制作它有点烦人.我正在寻找一种快速而优雅的方法.
我知道Spring具有注释的好方法,但是我在这个项目中没有使用spring.
最佳答案
请看一下我的SimpleJmx Java package,它旨在通过使用注释的JMX轻松发布bean.它还具有客户端代码.
快速代码示例:
// you can also use the platform mbean server
JmxServer jmxServer = new JmxServer(8000);
jmxServer.start();
// register our lookupCache object defined below
jmxServer.register(lookupCache);
...
jmxServer.stop();
这是定义bean的方法.
@JmxResource(domainName = "j256", description = "Lookup cache")
public class LookupCache {
@JmxAttributeField(description = "Number of hits in the cache")
private int hitCount;
...
@JmxOperation(description = "Flush the cache")
public void flushCache() {
...
}
}
欢迎反馈.