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?
CodePudding user response:
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);
}