Spring Boot 2.0 未注册自定义执行器端点 [英] Spring Boot 2.0 Not Registering Custom Actuator Endpoint

查看:32
本文介绍了Spring Boot 2.0 未注册自定义执行器端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将一个项目从 Spring Boot 1.5.1 升级到 2.0.0,但我们的自定义执行器端点未注册.我已经尝试了以下端点迁移指南(docs.spring.io, githubspring.io) 使用新方法迁移我们的自定义端点,但它不起作用.

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));
        }};
    }
}

我什至尝试从类中删除 @Component 并将其注册为我的主要 @Configuration 类中的 bean,如下所示:

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();
}

当我构建项目并启动时,我看到它注册了 /health/info/actuator 端点,但是不是我的 /time 端点.尝试转到 /time/actuator/time 会导致 404.

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)

我什至尝试升级到 2.0.1,但这也无济于事.

I even tried upgrading to 2.0.1, but that didn't help either.

我错过了什么?

推荐答案

我相信 Sharan De Silva 的回答是不正确的.我只是在一个相同的问题上花了几个小时,因为属性名称不同.应该是:

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'

这里是官方参考:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints-exposing-endpoints

这篇关于Spring Boot 2.0 未注册自定义执行器端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆