Reputation: 175
I have to check whether my service / app works or not.
I've added dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.6.2</version>
</dependency>
and also tried to add management.endpoint.health.show-details: always
to application.yml
but it didn't help.
I tried to go to http://localhost:8080/actuator/health
, http://localhost:8080/health
but it returned 404 error.
Upvotes: 8
Views: 24953
Reputation: 459
In my case, I had the spring-boot-starter-actuator
dependency, but did not have the spring-boot-starter-web
one - in a refactor, I thought it would not be needed as my application can run with spring.main.web-application-type: none
.
But that's not the case: turns out that if you set the web-application-type
property to none
and remove the spring-boot-starter-web
depdendency (after all, your application logic doesn't need any webserver running), the health endpoints will not be initialized (if you search in the application initialization logs, you will never find anything like
[main] INFO o.s.b.a.e.web.EndpointLinksResolver - Exposing *X* endpoints beneath base path '/actuator'
where X is the number of endpoints you defined in management.endpoints.web.exposure.include
.
This is super annoying, because in my assumption the health endpoints would enable a web server automatically, if needed.
So, my solution was adding:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
back to my pom.xml
, and live with the fact that my application runs a webserver only to expose those endpoints.
Upvotes: 2
Reputation: 1052
You can try this code on your application.yaml. This is worked for Spring boot 2.6.7.
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: health
Upvotes: 4
Reputation: 972
By default Spring boot enables security for all actuator endpoints
You can disable that feature using below property
management.security.enabled=false
Henceforth, try to run the application and hit the endpoint
http://localhost:8080/actuator
Upvotes: 0
Reputation: 789
As you see, you have 404 both on
http://localhost:8080/actuator/health
and
http://localhost:8080/health
Reason for this is not because security is enabled, if security was enabled you will get 401 or 403.
You probably need to expose actuator endpoints in application.yaml
file.
Something like this:
management:
endpoints:
web:
exposure:
include: "health,info"
And if you have security enabled, you need to write you own SecurityFilterChain
implementation in which you will disable security on all Actuator endpoints, or in your case only on those that you exposed in your application.yaml
file.
Example:
@Configuration
class ActuatorSecurityAutoConfiguration {
@Bean
SecurityFilterChain
surpassingActuatorSecurityFilterChain(HttpSecurity
httpSecurity) throws Exception {
return httpSecurity
.requestMatcher(EndpointRequest.toAnyEndpoint())
.authorizeRequests()
.anyRequest()
.permitAll()
.and().build();
}
}
Upvotes: 0