找不到MBean“jboss.web:type = Manager,path = /,host = localhost”

时间:2013-03-26 07:56:12

标签: java jboss jmx mbeans

我正在尝试访问注册为

JBoss v4.2 MBean
jboss.web:type=Manager,path=/,host=localhost

使用以下代码:

ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost");
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");

但是这段代码不断抛出以下异常:

javax.management.InstanceNotFoundException : jboss.web:type=Manager,path=/,host=localhost is not registered.

另一方面,我可以使用jmx-console通过... // localhost:8080 / jmx-console /来查看和使用这个bean。 - MBean可用。

Screenshot

通过代码访问同一MBean还需要什么?

1 个答案:

答案 0 :(得分:1)

发现它......

ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost");
this.sessions = new Long((Integer) MBeanServerLocator.locateJBoss().getAttribute(name, "activeSessions"));

我必须找到合适的MBeanServer ...... MBeanServerLocator.locateJBoss()解决它。