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

Spring boot 如何在Spring Boot中通过JMX公开TaskExecutor?,spring-boot,Spring Boot,在使用XML配置时,spring论坛上也提出并回答了类似的问题: 我希望避免使用XML。我使用的是Spring Boot 1.1.4,包括Spring Boot执行器。我的应用程序类如下所示: @Configuration @EnableAutoConfiguration @ComponentScan @EnableConfigurationProperties public class Application { // ... // this method is never

在使用XML配置时,spring论坛上也提出并回答了类似的问题:

我希望避免使用XML。我使用的是Spring Boot 1.1.4,包括Spring Boot执行器。我的应用程序类如下所示:

@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;
    }
}
@配置
@启用自动配置
@组件扫描
@EnableConfigurationProperties
公共类应用程序{
// ...
//永远不会调用此方法
@豆子
受保护的MBeanExporter MBeanExporter(){
MBeanExporter exporter=新的MBeanExporter();
Map bean=新的HashMap();
put(“org.springframework.boot:type=executor,name=taskExecutor”,taskExecutor());
出口植物(豆类);
退货出口商;
}
@豆子
受保护的AsyncTaskExecutor taskExecutor(){
ThreadPoolTaskExecutor executor=新的ThreadPoolTaskExecutor();
执行者。setCorePoolSize(5);
执行器setMaxPoolSize(200);
返还执行人;
}
}

可能还有另一个名为“mbeanExporter”的bean覆盖了您的bean。我认为这个习惯用法无论如何都是错误的,尽管a-您可能需要的是一个
MBeanInfoAssembler
(即使您必须将它插入具有不同bean名称的
MBeanExporter

您确定没有调用您的
MBeanExporter()
方法吗?如果是这样,如果在
application.properties
中设置
spring.jmx.enabled=false会发生什么?谢谢Dave,我将名称更改为myMbeanExporter(),并调用了它。只有这样,所有更改才能按预期工作,ThreadPoolTaskExecutor的属性才能通过JMX正确公开。