Announcement Announcement Module
No announcement yet.
Non-singleton beans w/JMX Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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="">
    <constructor-arg index="0"><value>100000</value></constructor-arg>

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

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