Question

I have a web application which has more than 40 Mbean. I used Spring Framework.

I am doing good and its working well. But i have 40 Mbean, so want to generalize the thing.

@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);
}

}

Now i have Same way Class YMbean, AMBean and so.

I configured the Spring in application mbean.xml.

<?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>

And same way i am going to preapre YMbean Class and in xml going to initialise.

What should i do that not require modification in XML Whatsoever or number of class i create ,dont require to update XML.

property is same in all Mbean which i am going to use. All ideas or input are welcome.

Thanks

Was it helpful?

Solution

Remove all of your configuration and replace with the use of the namespace and only once. Also your MBeans are @Components so you can simply scan for them. Which only would leave you with the following lines of xml

<context:component-scan base-package="in.projet.business.mbean" />
<context:mbean-export/>

Or if you want to keep your current configuration instead of the namespace replace it at least with the following and remove all other beans. This enables autodetection of MBeans in your application context (this is basically the same as the <context:mbean-export /> does.

For more information I strongly suggest the JMX chapter of the reference guide.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top