Announcement Announcement Module
No announcement yet.
Manually added beans in exporter work fine, but not autodetection Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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"/>

    <!-- (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"/>

    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)")
    @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)")
    @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.


    • #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:

      	<bean id="mbeanServer" class="" 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 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" />
      	<!-- Will pick up the ObjectName from the annotation. -->
          <bean id="namingStrategy"
              <property name="attributeSource" ref="jmxAttributeSource" />
      And here is the class I am trying to export:

      @ManagedResource(objectName="", description="Web Application Configuration")
      public class WebConfig {
      	private String protocol;
      	public String getProtocol() {
      		return protocol;
      	public void setProtocol(String protocol) {
      		this.protocol = protocol;


      • #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).


        • #5
          If it matters, I've filed ticket 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.


          • #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.


            • #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.


              • #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.


                • #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
                  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, 08:07 AM.