Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.0 Not Registering Custom Actuator Endpoint

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?

like image 496
james.lorenzen Avatar asked Oct 23 '25 16:10

james.lorenzen


2 Answers

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:

management:
  endpoints:
    web:
      exposure:
        include: 'health,info,metrics,customendpoint'

Here's the official reference: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints-exposing-endpoints

like image 141
Innokenty Avatar answered Oct 26 '25 06:10

Innokenty


management.endpoints.web.exposure.include={ENDPOINT-NAME}

like image 45
Birudeo Garande Avatar answered Oct 26 '25 07:10

Birudeo Garande



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!