Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-6851

autodetect of jmx mbeans either doesn't work, or not like the doc describes


    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: 2.5.6
    • Fix Version/s: None
    • Component/s: JMX
    • Labels:
    • Last commented by a User:


      I've been experimenting with trying to enable autodetection of JMX mbeans in my Spring context. Although I've had no trouble explicitly listing my mbeans in the "beans" property in the context, that's not quite optimal. I'm seeing more issues than the subject line describes, but I think they are issues with interpreting how this thing is supposed to work. It could be that all of the issues I'm seeing are just documentation problems, but I can't tell for certain.

      I'm using the @Managed... annotations in the bean class to specify the JMX attributes. I'd prefer to have them there than in the context. The only one that's somewhat questionable is the mbean name. I think I would want to set the "name=" part, but not the part before it (I'm not certain what the JMX-specific terms are for those pieces). For instance, in my class I currently have:

      objectName = "springjmxbug:name=logBean"

      it seems reasonable to set "logBean" in the class, but I think "springjmxbug" would be better set in the context.

      Despite the other questions about how this is supposed to work, in my testing, I've been unable to find an arrangement where autodetection will work, but it's entirely possible I'm misinterpreting how it's supposed to work.

      For instance, here's a short excerpt from my context:
      <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
      <property name="assembler" ref="assembler"/>
      <property name="autodetect" value="true"/>
      <property name="beans">
      <entry key="springjmxbug:name=logBean" value-ref="logManager"/>
      <bean id="logManager" class="springjmxbug.Log4JManager"/>
      <bean id="attributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>

      <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
      <property name="attributeSource" ref="attributeSource"/>

      Here's my "Log4JManager" class:
      @ManagedResource(objectName = "springjmxbug:name=logBean", description = "Bean for controlling Log4J levels in DynamicContent")
      public class Log4JManager {
      @ManagedOperation(description = "Set a Log4J logging level for a specific category (package)")

      { @ManagedOperationParameter(name = "packageName", description = "Log4J category name"), @ManagedOperationParameter(name = "level", description = "Log4J level") }

      public void setLogLevel(String packageName, String level)

      { LogManager.getLogger(packageName).setLevel(Level.toLevel(level)); }

      @ManagedOperation(description = "Get a Log4J logging level for a specific category (package)")

      { @ManagedOperationParameter(name = "packageName", description = "Log4J category name") }

      public String getLogLevel(String packageName)

      { return LogManager.getLogger(packageName).getLevel().toString(); }


      If I comment out the "beans" property, I get this very confusing error message:

      "Unable to register MBean [[email protected]] with key 'logManager'; nested exception is javax.management.MalformedObjectNameException: Key properties cannot be empty"

      Looking at the section in the doc that covers this, there is the following example:
      <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
      <property name="autodetect" value="true"/>
      <bean name="spring:mbean=true" class="org.springframework.jmx.export.TestDynamicMBean"/>

      There are a couple of confusing elements here. First, "autodetect" is set to true, but right there is the definition of the bean. If this is what is intended, then the meaning of "autodetect" is very different from what it means in the rest of Spring. Second, the definition of this bean using class "org.springframework.jmx.export.TestDynamicMBean" is odd, as there's no such class.

      I'm attaching a Maven project that I've been using to demonstrate these issues.




            • Assignee:
              david_syer Dave Syer
              dkarr David M. Karr
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created:
                Days since last comment:
                6 years, 23 weeks, 1 day ago