Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application fails to start with excluded health endpoint when JMX is enabled #28131

Closed
ThomasVitale opened this issue Sep 25, 2021 · 4 comments
Closed
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@ThomasVitale
Copy link

ThomasVitale commented Sep 25, 2021

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 #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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 25, 2021
@philwebb philwebb added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 26, 2021
@philwebb philwebb added this to the 2.6.x milestone Sep 26, 2021
@mbhave
Copy link
Contributor

mbhave commented Sep 27, 2021

@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?

@ThomasVitale
Copy link
Author

@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

@mbhave mbhave self-assigned this Sep 28, 2021
@ThomasVitale
Copy link
Author

ThomasVitale commented Sep 30, 2021

@mbhave I investigated a bit more and found the following.

  • When spring.jmx.enabled is set to true and the default Actuator configuration is used, the app starts up correctly.
  • When spring.jmx.enabled is set to true and the Actuator is explicitly configured to expose a few different endpoints including health, the app starts up correctly.
  • When spring.jmx.enabled is set to true and the Actuator is explicitly configured to expose a few different endpoints excluding health, the app does not start up correctly.
  • When spring.jmx.enabled is set to false and the Actuator is explicitly configured to expose a few different endpoints excluding health, 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

@mbhave
Copy link
Contributor

mbhave commented Sep 30, 2021

@ThomasVitale Thanks, this was the behavior that I observed as well.

@mbhave mbhave changed the title Actuator breaks in 2.6.0-M2+ due to the new additional health endpoint paths functionality Application fails to start with excluded health endpoint when JMX is enabled Oct 20, 2021
@mbhave mbhave closed this as completed in b7521e2 Oct 20, 2021
@mbhave mbhave modified the milestones: 2.6.x, 2.6.0-RC1 Oct 20, 2021
mbhave added a commit that referenced this issue Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants