Jirka Janák
Jirka Janák

Reputation: 33

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?

Upvotes: 3

Views: 1283

Answers (2)

M. Justin
M. Justin

Reputation: 21123

This was a bug in Spring Boot, and has since been fixed in Spring Boot 2.4.12 and 2.5.6. The fix is also present in versions 2.6.0 and later. Upgrading your version of Spring Boot will fix the issue.

Bug Fixes

  • When lazy initialization is enabled, JMX endpoints are not available #28335

Upvotes: 0

Andy Wilkinson
Andy Wilkinson

Reputation: 116091

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);
}

Upvotes: 1

Related Questions