相同的JMX Mbean类用于同一服务器上的许多应用程序

问题描述:

我有超过5个春季网络应用程序,所有这些都使用另一个公共库。这个公共库有自己的MBean。由于强制唯一objectName约束,我的应用程序无法部署在同一服务器上。

I have more than 5 spring web application and all of them are utilizing another common library. This common library has its own MBeans. Because of mandatory unique objectName constraint, my applications could not be deployed on same server.

我使用MBeans的方式是这样的:

The way I am using MBeans are like this:

@ManagedResource(objectName = "com.org.city:name=City", description = "City related operations")

我想为所有应用程序使用具有不同objectNames的相同MBean类。在不重复我的MBean的情况下使用它的正确方法是什么。

I would like to use same MBean class with different objectNames for all applications. What is the correct way to utilize it without duplicating my MBeans.

谢谢

我已经为自定义行为实现了ObjectNamingStrategy。

I have implemented ObjectNamingStrategy for custom behaviour.

   @Override
  public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
     Class managedClass = AopUtils.getTargetClass(managedBean);
     Hashtable<String, String> properties = new Hashtable<String, String>();
     properties.put("type",ClassUtils.getPackageName(managedClass).concat(".").concat(ClassUtils.getShortName(managedClass)));
     properties.put("name", beanKey);
     return ObjectNameManager.getInstance(domain, properties);
  }