Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.0 Not Registering Custom Actuator Endpoint Bean [duplicate]

I'm trying to add a custom actuator endpoint in Spring Boot 2.0.2.RELEASE application. I'm following the official guidelines, the official migration guide and also this post.

I am able to configure everything via properties: hide/expose endpoints, change base path etc. Everything works, except my custom endpoint bean is not picked up by WebMvcEndpointHandlerMapping. It simply doesn't show up in these famous logging lines:

EndpointLinksResolver        : Exposing 2 endpoint(s) beneath base path '/actuator'
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)

These three lines is all I get. I can access /actuator/health and /actuator/info without any trouble, but not my custom endpoint. I get 404 obviously.

What I tried so far:

  • Checked that my endpoint class is registered in the context as a bean.
  • Exposed it explicitly via yaml configuration.
  • Exposed everything via management.endpoints.web.exposure.include=*
  • Removed all the management configuration completely, because it should be actually available by default.
  • Triple checked the endpoint id.
  • Renamed the endpoint id.

Any ideas of what I can at least look into? All the questions I found so far end up in person not realizing they need @Component annotation too.

Ah, here is my class by the way:

@Component
@Endpoint(id = "hello")
public class HelloEndpoint {

    @ReadOperation
    public String sayHello() {
        return "Hello!";
    }
}
like image 316
Innokenty Avatar asked Nov 25 '25 13:11

Innokenty


1 Answers

After posting the question I found the answer almost immediately. It was a combination of typos in the config and the fact that it's actually not exposed by default. Despite the official post saying:

To configure an endpoint, all that’s required really is to expose it as a @Bean

These are the proper ways to define the property:

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.include='health,info,metrics,hello'

Or as a YAML:

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

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

Interesting, that you can't use underscores in endpoint names anymore. At least without additional changes.

like image 91
Innokenty Avatar answered Nov 28 '25 09:11

Innokenty



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!