Announcement Announcement Module
Collapse
No announcement yet.
Unique jmx object names with Spring JMX annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unique jmx object names with Spring JMX annotations

    Hi,

    I have a single class that is declared as two beans with two different bean ids.

    That class has the following jmx annnotation on it.

    Code:
    @ManagedResource("foo:type=bar")
    However when I start up Spring I get:

    Code:
    Caused by: javax.management.InstanceAlreadyExistsException: foo:type=bar
    How can I get Spring to use the bean id rather than what I supply as a value to the @ManagedResource annotation?

    I've already seen the property:
    http://static.springframework.org/sp...tNames(boolean)

    However this is already set to true by default and doesn't work.

    Do I need to implement my own ObjectNamingStrategy? If so would someone kindly provide an example?

    Much appreciate your help.

    Thanks.

  • #2
    I tried using the key naming strategy as below.

    Code:
        <bean id="exporter" class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
            <property name="autodetect" value="true" />
            <property name="ensureUniqueRuntimeObjectNames" value="true" />
            <property name="namingStrategy" ref="my.ObjectNamingStrategy" />
        </bean>
    
        <bean id="my.ObjectNamingStrategy" class="org.springframework.jmx.export.naming.KeyNamingStrategy">
            <property name="mappings">
                <props>
                    <prop key="myBean1">bean:name=myBean1</prop>
                    <prop key="myBean2">bean:name=myBean2</prop>
                </props>
            </property>
        </bean>
    However I now get the error:

    Code:
    Caused by: javax.management.MalformedObjectNameException: Key properties cannot be empty
    	at javax.management.ObjectName.construct(ObjectName.java:467)
    	at javax.management.ObjectName.<init>(ObjectName.java:1403)
    	at javax.management.ObjectName.getInstance(ObjectName.java:1285)
    	at org.springframework.jmx.support.ObjectNameManager.getInstance(ObjectNameManager.java:74)
    	at org.springframework.jmx.export.naming.KeyNamingStrategy.getObjectName(KeyNamingStrategy.java:140)
    	at org.springframework.jmx.export.MBeanExporter.getObjectName(MBeanExporter.java:751)
    	at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:654)
    	at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:615)
    	... 22 more

    Comment


    • #3
      I've now resolved this myself. Thanks.

      Comment


      • #4
        How did you resolve it? I'm getting the "Key properties cannot be empty" error.

        I have a config that looks like this:
        Code:
        <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
                <property name="beans">
                    <map>
                        <entry key="scheduleRevision">
                            <ref bean="scheduleRevision"/>
                        </entry>
                    </map>
                </property>
        </bean>

        Comment


        • #5
          How have you resolved this? please show us example. thanks.

          Comment

          Working...
          X