spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.8k stars 40.6k forks source link

spring boot 3.2.3, Actuator endpoints are treated as static resources #41480

Closed mindfultechies closed 2 months ago

mindfultechies commented 2 months ago

what are the possibilities that Spring treats /actuator endpoint as static content?

Config:

management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.endpoint.health.show-details=always
management.endpoint.metrics.enabled=true 

Log:

 Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver#679  trackingID:  Resolved [org.springframework.web.servlet.resource.NoResourceFoundException: No static resource actuator.]
o.s.w.s.DispatcherServlet#1138  trackingID:  Completed 404 NOT_FOUND
bclozel commented 2 months ago

Please share a sample application that demonstrates the problem.

mindfultechies commented 2 months ago

please find the sample code here. https://github.com/mindfultechies/sample-service.git. The sample code works fine with Intellij but it does not work with maven build and java -jar command

bclozel commented 2 months ago

I think your POM is probably misconfigured and the resulting jar is missing dependencies. Have you considered inheriting from the spring boot parent POM?

You can see it in action by creating a sample application on https://start.spring.io and adding the relevant parent section to your application.

Please let us know how that goes.

mindfultechies commented 2 months ago

thank you so much Brian. it works as expected after adding parent in pom. But still not clear about the significance of parent tag.

bclozel commented 2 months ago

I'm glad it works for you now. You'll find all the relevant information in the reference docs here.

My advice would be to use the parent POM provided by Spring Boot as it brings all the sensible defaults as well as repackaging configuration. If you need to use a different parent (like a parent POM provided internally by your company) you can learn how to do that in the next section of the same page.