Announcement Announcement Module
Collapse
No announcement yet.
Manually added beans in exporter work fine, but not autodetection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Manually added beans in exporter work fine, but not autodetection

    Using Spring 2.5.6.

    On the first try, I was able to define a bean, put it in the simple-minded exporter, and then jconsole was able to see the operations.

    I then wanted to add more information, as I didn't get nice parameter naming, and I thought that adding autodetection would be useful. Unfortunately, it doesn't appear to be autodetecting the bean.

    The relevant context excerpt is this:
    --------------------------
    <bean id="logManager" class="com.att.ecom.dynamiccontent.Log4JManager"/>

    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporte r">
    <property name="assembler" ref="assembler"/>
    <property name="autodetect" value="true"/>
    </bean>

    <!-- (for Java 5+ annotations-based metadata) -->
    <bean id="attributeSource" class="org.springframework.jmx.export.annotation.A nnotationJmxAttributeSource"/>

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

    The Log4jManager class is this:
    -----------------
    @ManagedResource(objectName = "bean: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)")
    @ManagedOperationParameters({
    @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.t oLevel(level));
    }

    @ManagedOperation(description = "Get a Log4J logging level for a specific category (package)")
    @ManagedOperationParameters({
    @ManagedOperationParameter(name = "packageName", description = "Log4J category name")
    })
    public String getLogLevel(String packageName) {
    return LogManager.getLogger(packageName).getLevel().toStr ing();
    }
    }
    ----------------

  • #2
    Note that my only Spring context is in "WEB-INF/applicationContext.xml". I don't have a <name>-servlet.xml file. I'm using the ContextLoaderListener, and I'm not using a DispatcherServlet.

    My workaround for this problem is manually defining my bean in the "beans" property of the exporter, but I thought the point of automatic detection of mbeans was that I didn't have to do that.

    Comment


    • #3
      I am having the exact same problem using Spring 3. It would be great if anyone has a solution to this. I can manually specify the beans and they show up in jmx-console. But Spring is not picking up my mbeans automatically.

      Here is my configuration on JBoss that works just as dkarr describes:

      Code:
      	<bean id="mbeanServer" class="org.jboss.mx.util.MBeanServerLocator" factory-method="locateJBoss" />
      	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
      		<property name="server" ref="mbeanServer" />
      		<property name="autodetect" value="true" />
      		<property name="assembler" ref="assembler" />
      			
      	</bean>
      	<bean id="jmxAttributeSource"
                class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
      	
      	<!-- Will create management interface using annotation metadata. -->
      	<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
      		<property name="attributeSource" ref="jmxAttributeSource" />
      	</bean>
      	
      	<!-- Will pick up the ObjectName from the annotation. -->
          <bean id="namingStrategy"
                class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
              <property name="attributeSource" ref="jmxAttributeSource" />
          </bean>
      And here is the class I am trying to export:

      Code:
      @ManagedResource(objectName="com.so.config:name=WebConfig", description="Web Application Configuration")
      public class WebConfig {
      	
      	private String protocol;
      
      	@ManagedAttribute(defaultValue="https")
      	public String getProtocol() {
      		return protocol;
      	}
      
      	@ManagedAttribute(defaultValue="http")
      	public void setProtocol(String protocol) {
      		this.protocol = protocol;
      	}
      
      }

      Comment


      • #4
        That convinces me that we've found a bug. I had already started to think about building a small maven-built app to demonstrate this for a ticket, but I've been having trouble with m2eclipse (my normal work uses Ant). If you can build a minimal test case for this with maven, file a ticket for this and attach the test case (and reply back here if you file a ticket).

        Comment


        • #5
          If it matters, I've filed ticket https://jira.springsource.org/browse...s:all-tabpanel for this. I think it's possible the documentation implies things that are not true, based on what we expect from an "autodetect" attribute in Spring.

          Comment


          • #6
            Thanks dkarr, for opening the ticket. I think you are right in that the documentation/naming conventions are deceiving. But it would also be nice if the beans did in fact get auto-detected without having to specify them via XML.

            Comment


            • #7
              If someone is running into an issue similar to this, I think I discovered something that clears this up.

              I think the combination of a "@ManagedResource"-annotated class and a "context:mbean-export" element in the context will result in Spring automatically exporting that class as a JMX MBean, but ONLY if there is an explicit bean definition in the context, or more reasonably, if you also add a "@Component" annotation to the annotated class.

              I think the point is that "@ManagedResource" will cause the bean associated with this class to be exported, but only if the bean exists, and "@ManagedResource" is not like "@Component", "@Service", et cetera, which will be found when "context:component-scan" is used.

              So, the conclusion is that you need both "@Component" and "@ManagedResource" on a class if you don't have it otherwise specified as a bean in the context.

              Comment


              • #8
                Did you not understand my last reply on this thread (that I started)? The point is that @ManagedResource only specifies how the managed bean will be exported as an mbean. By itself that will not cause the bean to be created, and if the bean isn't created, the mbean won't be exported.

                The solution is to add the @Component annotation, along with "context:component-scan" in the application context.

                Comment


                • #9
                  Many answers you have found to solve your problem. One thing is that you have to specify the full object name in the filter criteria to get the MBean attributes. You can get the list of all the MBeans by clicking on "Show MBeans button". Select the MBean by enabling the check box provided alongside.
                  supported living community
                  Glenvale Supported Living
                  182-184 Hursley Road Toowoomba QLD 4350 Australia
                  Phone : +61 1300 765 051
                  http://www.glenvalesupportedliving.com.au/
                  Providing community aged care supported living housing in Toowoomba, the Glenvale Villas are the perfect option for your loved ones, if they need a little extra help with daily living.
                  Last edited by Konrad78; Feb 9th, 2013, 09:07 AM.

                  Comment

                  Working...
                  X