Question

I have a problem managing a class in JMX. I exposed it to JMX, and set the manageable methods and attributes of my class by adding annotation but when I open my bean in the JConsole it exposed all the methods and it prints me the output like illustrated in the screenshot below :

enter image description here

I can still use my exposed methods without any problems but it's a bit annoying to allways have this error's window popping and to have to scroll down to find my exposed methods.

Here is how I declared my bean :

   <bean name="MBeanExporter" class="org.springframework.jmx.export.MBeanExporter">
      <property name="beans">
         <map>
            <entry key="SmartTrade:name=tickEngine" value-ref="aggregationEngine" />
         </map>
      </property>
   </bean>

with aggregationEngine is a reference to my class :

<bean name="aggregationEngine" class="com.smarttrade.tick.engine.TickEngine">
   <!--       list of properties .... -->
</bean>

and here a part of my class where you can see that setTickDataReader(..) is not exposed but still appears in the JConsole, and also how I made my annotations for the good methods :

public void setTickDataReader(TickDataReader tickDataReader) {
    this.tickDataReader = tickDataReader;
}


public void setEnabled(boolean enabled) {
    this.enabled = enabled;
}

@ManagedOperation(description = "Activate or deactivate tick data")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "enable", description = "boolean") })
public void enableTickData(boolean enable) {
    this.enabled = enable;
    if (enabled) {
        init();
    } else {
        unsubscribe();
    }
}

Any idea of where it can come from ? Thanks in advance.

Was it helpful?

Solution

The org.springframework.jmx.export.MBeanExporter by default uses the org.springframework.jmx.export.assembler.SimpleReflectiveMBeanInfoAssembler. Which effectively exposes all the public methods to JMX.

To only have your annotated methods exported either switch to using the org.springframework.jmx.export.annotation.AnnotationMBeanExporter or set the namingStrategy and assembler property in such a way that it uses annotation processing (which is basically what the org.springframework.jmx.export.annotation.AnnotationMBeanExporter also does).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top