问题
I'm trying to access the JBoss v4.2 MBean registered as
jboss.web:type=Manager,path=/,host=localhost
using the following code:
ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost");
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");
But this code keeps throwing the following exception:
javax.management.InstanceNotFoundException : jboss.web:type=Manager,path=/,host=localhost is not registered.
On the other hand I'm able to see and use this bean using the jmx-console via ...//localhost:8080/jmx-console/ - the MBean is available.
What else is necessary to access the same MBean via code?
回答1:
Found it...
ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost");
this.sessions = new Long((Integer) MBeanServerLocator.locateJBoss().getAttribute(name, "activeSessions"));
I had to find the right MBeanServer... MBeanServerLocator.locateJBoss()
solves it.
来源:https://stackoverflow.com/questions/15632000/mbean-jboss-webtype-manager-path-host-localhost-not-found