Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Spring Boot Actuator available via JMX with globally enabled lazy initialization?

In our Spring Boot 2.4+ based applications we need to have configured that initialization should be performed lazily in application.properties:

spring.main.lazy-initialization=true
spring.jmx.enabled=true

However with such settings Actuator end-points cannot be reached via JMX.

This is a blocker now when we are migrating to Instana monitoring, which requires org.springframework.boot:type=Endpoint,name=Metrics and org.springframework.boot:type=Endpoint,name=Health MBeans to be available via JMX.

Is there a way to keep lazy initialization enabled but at the same Actuator accessible via JMX, please?

like image 320
Jirka Janák Avatar asked Nov 21 '25 19:11

Jirka Janák


1 Answers

This is a bug in Spring Boot for which I've just opened an issue. Thanks for bringing it to our attention.

You can work around the problem by excluding the bean that exports the endpoints to JMX from lazy initialization. To do so, add the following bean to your application:

@Bean
LazyInitializationExcludeFilter eagerJmxEndpointExport() {
    return LazyInitializationExcludeFilter.forBeanTypes(JmxEndpointExporter.class);
}
like image 166
Andy Wilkinson Avatar answered Nov 24 '25 23:11

Andy Wilkinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!