As an equivalent to Spring XML's <context:mbean-export/>
element,
JavaConfig provides the @MBeanExport
annotation.
/** * A performance monitor that implements a JMX MBean interface */ public class PerformanceMonitor implements PerformanceMonitorMBean { public int getHitCount() { return hitCount; } // ... } public interface PerformanceMonitorMBean { int getHitCount(); // ... }
/** * A @Configuration class that wires up a PerformanceMonitor bean and ensures * it is registered with the local MBean server using @MBeanExport */ @Configuration @MBeanExport public class Config { // declare the MBean class as a spring bean @Bean public PerformanceMonitor performanceMonitor() { return new PerformanceMonitor(); } }
Note | |
---|---|
Like with <context:mbean-export/> , MBean classes can be defined
in a number of ways - using traditional MBean interfaces as shown above, or with
Spring's @ManagedResource and associated annotations, etc. See the
core Spring Framework
documentation on JMX support for details.
|