spring - 将从工厂创建的SimpleMessageListenerContainer暴露为mbean

时间:2015-11-15 04:42:58

标签: spring spring-jmx

使用弹簧4.我正在创建一个

SimpleMessageListenerContainer

来自工厂方法

@Configuration @Bean

        @Bean( name = "container" )
        SimpleMessageListenerContainer container(){
...
...

如何在JMX上公开此实例?由于@ManagedResource只能应用于类

1 个答案:

答案 0 :(得分:0)

@Bean
public MBeanExporter exporter() {
    MBeanExporter mBeanExporter = new MBeanExporter();
    mBeanExporter.setBeans(
        Collections.singletonMap("myDomain:type=container,name=myContainter", "container"));
    return mBeanExporter;
}

这将公开所有公共方法/属性。如果您希望限制暴露的内容,可以使用MethodNameBasedMBeanInfoAssembler

@Bean
public MBeanExporter exporter() {
    MBeanExporter mBeanExporter = new MBeanExporter();
    mBeanExporter.setBeans(
        Collections.singletonMap("myDomain:type=container,name=myContainter", "container"));
    MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler();
    assembler.setManagedMethods(new String[] { "start", "stop" });
    mBeanExporter.setAssembler(assembler);
    return mBeanExporter;
}