This article is about how to create MBeans using annotations and spring. It assumes that you already have a MBean server available like the one in tomcat. Just follow the steps below.

First we want to create a Mbean, using the @Managed annotations you can convert any class you want into a MBean. The class MyMBean below 2.8.1 is a very simple one which will only expose one Brisbane-Ipswich method (i.e. getSomething). The @ManagedResource annotation will mark the class as a MBean. The @ManagedAttribute and @ManagedOperation annotations Снятие can be used to expose any cheap nba jerseys attributes or methods. Also notice Parents the @Component annotation, this SSH annotation will make the MBean eligible for the spring context scanner.


import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;

@ManagedResource(objectName = "MyApp:name=MyMbean")
public class MyMBean {

	@ManagedOperation(description = "Returns something.")
	public String getSomething() {
		return "Something";


Next, you will have to create a MBeanExporter in your spring application context. Normally just adding the <context:mbean-export/> element will do the trick but not in this case. You need a JmxAttributeSource which is capable of reading the @ManagedResouce annotations. The downside is that we have to make a more elaborate configuration which is not as beautiful as the short <context:mbean-export/> element.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi="" 
   wholesale mlb jerseys    xsi:schemaLocation="">

    <!-- this  New  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="assembler" ref="assembler" />
        <property name="namingStrategy" ref="namingStrategy" />
        <property name="autodetect" value="true" />
    cheap jerseys online   </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" />

    <!-- will pick up the ObjectName from the annotation -->
    <bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
        <property name="attributeSource" ref="jmxAttributeSource" />

But now spring still will not find any of your MBeans. Remember the cheap nba jerseys @Component annotation (or @Named annotation wholesale jerseys if you are using jsr 330) at the class declaration of your MBean? Adding the component-scan element to your spring application context configuration will make sure all classes annotated with @Component, @Service or @Repository will be added to the spring context.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi=""  Included  

    <context:component-scan base-package="" />


That’s it. Good look with it.

Spring Framework Reference JMX