Announcement Announcement Module
No announcement yet.
JConsole doesn't display setter operation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JConsole doesn't display setter operation

    I'm using annotations and Spring's auto discovery mode to build the MBeans during start up. The class that has the setter as well as several attributes has the following class annotation:

    @ManagedResource(objectName="RPMController.DB:name=Hibernate", description="Hibernate Database")
    The method with the setter:

    	 * @see StatisticsServiceMBean#setStatisticsEnabled(boolean)
    	@ManagedOperation(description="Enable Statistics")
        @ManagedOperationParameter(name="enable",description="Set true to enable statistics")})
        public void setStatisticsEnabled(boolean enable) {
    	 * @see StatisticsServiceMBean#isStatisticsEnabled()
    	@ManagedAttribute(description="Statistics Enabled")
    	public boolean isStatisticsEnabled() {
    		return stats.isStatisticsEnabled();
    The isStatisticsEnabled() along with all the other defined attributes are displayed in the JConsole Operations tab. However, the setStatisticsEnabled(boolean enable) operation does not display.

    Can someone explain what I'm doing wrong?

  • #2
    Use @ManagedAttribute for Setter/Getter

    The setStatisticsEnabled method does not show up as a Spring-JMX-exposed operation because it has the annotation @ManagedOperation applied to it rather than @ManagedAttribute. If you change that to @ManagedAttribute, it should work for you.

    For additional details, see the blog entry Using Spring Metadata MBean Exporting for Greater Descriptive Detail.


    • #3
      Can you point me to a URL that explains these two annotations? I thought the @ManagedOperation was for the setting of a value or the initiation of a process, and @ManagedAttribute was for passive attributes.


      • #4
        Remove "set" in method name to use @ManagedOperation

        If you change your method's name from setStatisticsEnabled to something without "set" in it [such as changeStatisticsEnabled(boolean) or markStatisticsEnabled(boolean)], this should work for you. I believe that any method with "get" or "set" in it (method names that satisfy the JavaBeans getter/setter definition) needs to be annotated with @ManagedAttribute and any method without "get" or "set" needs to be annotated with @ManagedOperation.

        I am not aware of a URL that points to this being the case definitively, but this has been my observation from dabbling with Spring's JMX support.


        • #5
          Thank you - that helps