Starting from Spring Boot 2.6.0-M2, the Spring Boot Actuator fails during the application startup when the health endpoint is not included in the management.endpoints.web.exposure.include property. It looks like that scenario triggers Actuator to use the new functionality added in https://github.com/spring-projects/spring-boot/issues/25471 for supporting additional health endpoint paths, even if no configuration has been provided for that.
It's probably not that common to use Actuator without leveraging the useful health endpoint, but if that happens, it's a breaking issue when upgrading to Spring Boot 2.6.0+ (the error is not present in 2.5.5).
I made a small demo application you can run and see more details in the logs about the error thrown during the startup. https://github.com/ThomasVitale/spring-boot-additonal-health-group
An extract of the error message:
Error creating bean with name 'healthEndpointWebMvcHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration$MvcAdditionalHealthEndpointPathsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.AdditionalHealthEndpointPathsWebMvcHandlerMapping]: Factory method 'healthEndpointWebMvcHandlerMapping' threw exception; nested exception is java.util.NoSuchElementException: No value present
Comment From: mbhave
@ThomasVitale I was not able to reproduce the behavior with the provided sample. However, if I add spring.jmx.enabled; true to application.yml, I see the error you've described. Could you confirm if that's what you're seeing as well?
Comment From: ThomasVitale
@mbhave When I run the app I referenced, I get the following error message at startup. If I don't provide any Actuator configuration at all, then the application starts up correctly (even if spring.jmx.enabled is set to true).
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpointWebMvcHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration$MvcAdditionalHealthEndpointPathsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.AdditionalHealthEndpointPathsWebMvcHandlerMapping]: Factory method 'healthEndpointWebMvcHandlerMapping' threw exception; nested exception is java.util.NoSuchElementException: No value present
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.10.jar:5.3.10]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.10.jar:5.3.10]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:719) ~[spring-boot-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:401) ~[spring-boot-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1279) ~[spring-boot-2.6.0-M3.jar:2.6.0-M3]
at com.example.demo.DemoApplication.main(DemoApplication.java:12) ~[main/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.AdditionalHealthEndpointPathsWebMvcHandlerMapping]: Factory method 'healthEndpointWebMvcHandlerMapping' threw exception; nested exception is java.util.NoSuchElementException: No value present
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.10.jar:5.3.10]
... 19 common frames omitted
Caused by: java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:143) ~[na:na]
at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointWebExtensionConfiguration.getHealthEndpoint(HealthEndpointWebExtensionConfiguration.java:79) ~[spring-boot-actuator-autoconfigure-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointWebExtensionConfiguration.access$000(HealthEndpointWebExtensionConfiguration.java:66) ~[spring-boot-actuator-autoconfigure-2.6.0-M3.jar:2.6.0-M3]
at org.springframework.boot.actuate.autoconfigure.health.HealthEndpointWebExtensionConfiguration$MvcAdditionalHealthEndpointPathsConfiguration.healthEndpointWebMvcHandlerMapping(HealthEndpointWebExtensionConfiguration.java:89) ~[spring-boot-actuator-autoconfigure-2.6.0-M3.jar:2.6.0-M3]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.10.jar:5.3.10]
... 20 common frames omitted
Comment From: ThomasVitale
@mbhave I investigated a bit more and found the following.
- When
spring.jmx.enabledis set totrueand the default Actuator configuration is used, the app starts up correctly. - When
spring.jmx.enabledis set totrueand the Actuator is explicitly configured to expose a few different endpoints includinghealth, the app starts up correctly. - When
spring.jmx.enabledis set totrueand the Actuator is explicitly configured to expose a few different endpoints excludinghealth, the app does not start up correctly. - When
spring.jmx.enabledis set tofalseand the Actuator is explicitly configured to expose a few different endpoints excludinghealth, the app starts up correctly.
I have updated my example app, including an auto test that now fails and shows the error: https://github.com/ThomasVitale/spring-boot-additonal-health-group/blob/main/src/test/java/com/example/demo/DemoApplicationTests.java
Comment From: mbhave
@ThomasVitale Thanks, this was the behavior that I observed as well.