Results 1 to 2 of 2

Thread: Non-singleton beans w/JMX

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Default Non-singleton beans w/JMX

    I have a bean that needs to be created on the fly (thus non-singleton) while my application is loading. I am trying to have Spring auto-detect the non-singleton bean and wrap each instance so that I can monitor them (each instance is an event queue), but what I have noticed is that Spring seems to instantiates an instance of the bean that it uses to export as the mbean, and the other instances that are created by bean lookup in my application are not exported as mbeans. I looked at the code in for MBeanExporter and it looks like if the bean is not lazy-init enabled, it will create an instance via bean lookup. As non-singleton beans cannot be marked lazy-init I am not sure what to do. I appreciate any help.

    <bean id="eventProcessorImpl" singleton="false" class="com.xyz.tomahawk.core.EventProcessorImpl">
    <constructor-arg index="0"><value>100000</value></constructor-arg>
    </bean>



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

    <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>

    <bean id="namingStrategy" class="org.springframework.jmx.export.naming.Metad ataNamingStrategy">
    <property name="attributeSource" ref="attributeSource"/>
    </bean>
    Last edited by bcritch; Jun 5th, 2006 at 11:46 AM.

  2. #2
    Join Date
    Jun 2006
    Posts
    2

    Unhappy

    based on what I have found by looking through the spring code, is that if you add a non-singleton bean to the MBeanExporter's beans map, it will instantiate a copy of the bean and enable it for JMX. This is obviously not desired behavior. The only way I have found to actually properly register (through MBeanExporter) eachh instance of a non-singleton is to get the exporter from the appContext and directly register the non-singleton after you have created it.

    It would be a fairly nice extension (IMO) if the spring framework could support it a bit more seamlessly - but as there is a workaround our problem is solved for now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •