I've recently upgraded a project from Spring Boot 1.5.1 to 2.0.0 and our custom actuator endpoint is not getting registered. I've tried the following endpoint migration guides (docs.spring.io, github, and spring.io) to migrate our custom endpoint with the new approach but it doesn't work.
Here is a simplified endpoint I'm trying to register:
@Component
@Endpoint(id = "time")
public class TimeEndpoint {
@ReadOperation
public Map<String, Object> getTimeInfo() {
return new HashMap<String, Object>() {{
put("time", DateTime.now(UTC));
}};
}
}
I've even tried removing the @Component
from the class and registering it as a bean in my main @Configuration
class like the following:
@Bean
public TimeEndpoint timeEndpoint() {
return new TimeEndpoint();
}
When I build the project and start up, I see it registering the /health
, /info
, and /actuator
endpoints, but not my /time
endpoint. Attempting to go to /time
or /actuator/time
results in a 404.
WebMvcEndpointHandlerMapping - Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
WebMvcEndpointHandlerMapping - Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
WebMvcEndpointHandlerMapping - Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
I even tried upgrading to 2.0.1, but that didn't help either.
What am I missing?
You need to expose your custom endpoint by adding this to your
application.yml
file.If you want to expose all your endpoints then change it as
expose: '*'
I believe, the answer by Sharan De Silva is not correct. I just spent several hours on a identical issue, because the property name is different. Should be:
Here's the official reference: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints-exposing-endpoints