我有一个超过 40 Mbean 的 Web 应用程序。我使用了 Spring 框架。
我做得很好,它运作良好。但我有 40 Mbean,所以想概括一下。
@Component
@ManagedResource(objectName="ProjectCache:name=XMBean", log=true, logFile="jmx.log")
public class XMBean extends AbstractCacheMBean<String, XCO, XCache> {
@ManagedOperation(description ="ProjectCache XCO key")
@Override
public List<String> showAllKeys(){
return super.getKey();
}
@ManagedOperation(description ="ProjectCache XCO")
public List<String> showAllElements(){
return super.findAll();
}
@Override
public XCache getCache() {
return getFacadeCache().getXCache();
}
@ManagedOperation(description ="ProjectCache XCO by key)
@Override
public String ShowbyKey(String key) {
return super.findbyKey(key);
}
}
现在我有相同的方式类 YMbean、AMBean 等。
我在应用程序 mbean.xml 中配置了 Spring。
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/beans"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- this bean must not be lazily initialized if the exporting is to happen -->
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="server" ref="mbeanServer"/>
<property name="assembler" ref="assembler" />
<property name="namingStrategy" ref="namingStrategy" />
</bean>
<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
<!-- will create management interface using annotation metadata -->
<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource" />
</bean>
<!-- will pick up the ObjectName from the annotation -->
<bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
<property name="attributeSource" ref="jmxAttributeSource" />
</bean>
<bean id="xMBean"
class="in.projet.business.mbean.XMBean">
<property name="memoryCache" ref="repository" />
</bean>
同样,我将准备 YMbean 类并在 xml 中进行初始化。
我应该做什么不需要在 XML 中修改无论我创建的类或数量如何,都不需要更新 XML。
我要使用的所有 Mbean 的属性都是相同的。欢迎所有想法或意见。
谢谢