How can I open TaskExecutor over JMX in Spring Boot?

A similar question was asked and answered in the spring forums when using the XML configuration:

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

I would like to avoid using XML. I am using spring boot 1.1.4 and have included spring-boot-actuator. The My Application class is as follows:

@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;
    }
}
+4
source share
1 answer

Probably another bean called "mbeanExporter" overrides yours. I think the idiom is wrong in any case, although perhaps you need to MBeanInfoAssembler(even if you need to connect it to MBeanExporterwith a different bean name).

+1

All Articles