如何在Spring Boot中通过JMX公开TaskExecutor?

时间:2014-08-01 01:03:42

标签: spring-boot

使用XML配置时,在春季论坛中提出并回答了类似的问题:

http://forum.spring.io/forum/spring-projects/integration/723982-i-cant-figure-out-how-to-expose-task-executor-vai-jmx?p=724001#post724001

我想避免使用XML。我正在使用Spring Boot 1.1.4,并且包含了spring-boot-actuator。我的Application类看起来像这样:

@Configuration
@EnableAutoConfiguration
@ComponentScan
@EnableConfigurationProperties
public class Application {
    // ...

    // this method is never called
    @Bean
    protected MBeanExporter mbeanExporter() {
        MBeanExporter exporter = new MBeanExporter();
        Map<String,Object> beans = new HashMap<>();
        beans.put("org.springframework.boot:type=executor,name=taskExecutor", taskExecutor());
        exporter.setBeans(beans);
        return exporter;
    }

    @Bean
    protected AsyncTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(200);
        return executor;
    }
}

1 个答案:

答案 0 :(得分:1)

可能还有另一种名为&#34; mbeanExporter&#34;压倒你的。我认为这个成语虽然是错误的 - 你可能需要的是MBeanInfoAssembler(即使你必须将它插入到具有不同bean名称的MBeanExporter中)。