Change @ManagedResource objectName dynamically

I am creating prototype beans programatically/dynamically. I want those beans after initiation to be in the jmx console. How I can distinguish between them? I am using anotations in order to add my beans to the jmx and I have


I need to inject the objectName dynamically. Any idea how could I do it?

Here's my jmx configuration:

<context:mbean-export server="mbeanServer" />

<bean id="mbeanServer" class="" />

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"

        <property name="beans">
                <entry key="Server:name=HttpAdaptor">
                    <bean class="">
                        <property name="port" value="8000" />
                        <property name="host" value="" />
                        <property name="processor">
                            <bean class="" />

        <property name="listeners">

                <bean class="com.fixgw.jmx.HttpAdaptorMgr">
                    <property name="mbeanServer" ref="mbeanServer" />

   <bean id="sessionMDB" class="com.fixgw.mdb.SessionMDB"
        scope="prototype" lazy-init="true">
        <constructor-arg ref="0" />
        <constructor-arg ref="0" />


You can use a a JMX naming strategy to do this. At work we use an interface:

public interface RuntimeJmxNames {
    /** this is the name= part of the object name */
    public String getJmxName();
    /** this sets the folders as 00=FirstFolder,01=Second */
    public String[] getJmxPath();

I've posted the code to implement the RuntimeMetadataNamingStrategy naming strategy.

And then something like the following Spring beans:

<bean id="jmxAttributeSource"
 class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />

<bean id="jmxAssembler"
    <property name="attributeSource" ref="jmxAttributeSource" />

<bean id="jmxNamingStrategy" class="com.j256.jmx.RuntimeMetadataNamingStrategy">
    <property name="attributeSource" ref="jmxAttributeSource" />

<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="autodetect" value="true" />
    <property name="assembler" ref="jmxAssembler" />
    <property name="namingStrategy" ref="jmxNamingStrategy" />
    <property name="ensureUniqueRuntimeObjectNames" value="false" />
    <property name="excludedBeans" ref="excludedJmxBeans" />

In your code you do something like:

@ManagedResource(objectName = "", description = "...")
public class Foo implements RuntimeJmxNames {
    public String getJmxName() {
        // here's where you can make the name be dynamic
        return toString();
    public String[] getJmxPath() {
        return new String[] { "folder" };

Here's the Spring documentation on JMX naming although I'm not 100% sure it covers the custom naming stuff.

Also, my SimpleJMX package does a this as well. It uses a JmxSelfNaming interface which allows each instance of an object to define it's own bean-name to make them unique and works well with Spring.

You can do this by just implementing org.springframework.jmx.export.naming.SelfNaming:

public class MyPrototypeScopedBeanName implements SelfNaming
    public ObjectName getObjectName() throws MalformedObjectNameException {
        return new ObjectName("com.foobar", "name", this.toString());

Need Your Help

Overlaying short video files on Linux? (ffmpeg)

merge ffmpeg video-processing

Does ffmpeg or any other tool support merging/overlaying (not concatenating) of video files?

My jQuery UI Autocomplete not working?

jquery ajax json jquery-ui jquery-ui-autocomplete

Here I am trying to implement the jQuery I have two main files one is db.php which hold this thing: