Feb 16 2009
Exposing MBeans with Spring
Websphere specifics
![]()
In the above example, annotation has a naming convention for objectName. It is "domain:key=value". Later on, Spring class "org.springframework.jmx.support.MBeanRegistrationSupport will fetch the domain and use it to register the MBean to MBeanServer. The domain can be used to group the registered MBeans.
IBM Websphere handles MBeans a little different than most Java EE servers. Whenever one registers an MBean within Websphere the container will 'extend' its name to include the actual deployment location of the bean. This is required to avoid conflicts when registering beans in clusters and or cells of servers.
This behavior complicates things when one needs to unregister an MBean. the actual name needed to unregister the MBean is unknown to the application as it has been altered by Websphere. Unregistering and registering beans is required when one restarts an application without restarting the Websphere server it runs on. If this action is not performed new performance data will not be exposed.
The best approach is to implement org.springframework.jmx.export.naming.ObjectNamingStrategy, which is an interface that encapsulates the creation of ObjectName instances and is used by the MBeanExporter to obtain ObjectNames when registering beans. An example is available on the Spring Framework forum. You can add the ObjectNamingStrategy instance to the bean that you register. This will ensure that the MBean is properly de-registered when the application is uninstalled.
Get ahold of WebSphere's admin service
<bean id="adminService" class="com.ibm.websphere.management.AdminServiceFactory" factory-method="getAdminService"/>
Get the bits from the admin service needed for the object name.
-
<bean id="adminService.defaultDomain" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
-
<bean id="adminService.cellName" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
-
<bean id="adminService.nodeName" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
-
<bean id="adminService.processName" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
Create the WebSphere object naming strategy
-
<bean id="websphereNamingStrategy" class="WebsphereNamingStrategy">
-
<property name="domainName" ref="adminService.defaultDomain"/>
-
<property name="cellName" ref="adminService.cellName"/>
-
<property name="nodeName" ref="adminService.nodeName"/>
-
<property name="processName" ref="adminService.processName"/>
-
</bean>
Export someBean with using the WebSphere object naming strategy.
-
<bean id="beanExporter" class="org.springframework.jmx.export.MBeanExporter">
-
<property name="beans">
-
<map>
-
<entry key="someBean" value-ref="someBean"/>
-
</map>
-
</property>
-
<property name="namingStrategy" ref="websphereNamingStrategy"/>
-
</bean>
WebSphere Object Naming Strategy. Creates an object name with the WebSphere required bits.
-
public class WebsphereNamingStrategy implements ObjectNamingStrategy
-
{
-
private String domainName;
-
private String cellName;
-
private String nodeName;
-
private String processName;
-
-
throws MalformedObjectNameException
-
{
-
objectName.append(domainName);
-
objectName.append(":cell=");
-
objectName.append(cellName);
-
objectName.append(",name=");
-
objectName.append(name);
-
objectName.append(",type=");
-
objectName.append(ClassUtils.getShortName(object.getClass()));
-
objectName.append(",node=");
-
objectName.append(nodeName);
-
objectName.append(",process=");
-
objectName.append(processName);
-
-
return ObjectNameManager.getInstance(objectName.toString());
-
}
-
-
return cellName;
-
}
-
-
this.cellName = cellName;
-
}
-
-
return domainName;
-
}
-
-
this.domainName = domainName;
-
}
-
return nodeName;
-
}
-
-
this.nodeName = nodeName;
-
}
-
-
return processName;
-
}
-
-
this.processName = processName;
-
}
-
}


I was trying to set up a JMX managed standalone Spring application and the article helped a lot. Thanks!!!
Hello, I found your post about the Spring mbeans in the WebSphere 6.1. I am new to Spring and JMX and looking for a step by step guide to register and calling by wsadmin some Spring’s mbeans provided by the app developer. I read your post and do understand the websphere naming strategy but where do I need to place this class WebsphereNamingStrategy ?
br
Mark
Hello Mark,
You can place your WebsphereNamingStrategy class where you want. For my part, I place it in an “util” package…
Cheers,
Gilles
Hello Gilles,
Thanks a lot for a quick response. I just have one question if there is any possibility to enable the Spring’s mbean in WAS 6.1 without adding any new code to the project ? I do not have the source code and do not want to extend the EAR file.
br
Mark
excellent info, thanks!
was trying to get this running on websphere and also figured out that websphere changes the objectnames of the mbeans..your sources saved a lot of time for me yeehaa