Search code examples
javajmxapache-tomeembeans

How to specify name of mbean with annotation @MBean


I have SAR archive for JBoss and there is one MBean registered in jboss-service.xml. Now I want to migrate to TomEE and use standard javax.management annotation @MBean, but I can't find out how to specify name of it and it creates with default name. Can anyone help me?


Solution

  • You have to specify the name when registering the bean as described here:

      MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
      ObjectName name = new ObjectName("com.example.mbeans:type=Hello"); 
      Hello mbean = new Hello(); 
      mbs.registerMBean(mbean, name);