【问题标题】:Spring Boot Actuator not showing any informationSpring Boot Actuator 不显示任何信息
【发布时间】:2020-03-02 22:32:50
【问题描述】:

我正在使用 Spring Boot 版本 2.2.5.RELEASE 并且无法从执行器端点接收任何信息。我收到的只是 Actuator 的空结构,如下所示:

这是我的配置:

implementation "org.springframework.boot:spring-boot-starter-actuator"
@Bean
public HttpTraceRepository httpTraceRepository() {
   return new InMemoryHttpTraceRepository();
}
management:
  endpoints:
    web:
      exposure:
        include: "*"

我错过了什么?

【问题讨论】:

    标签: java spring-boot heroku spring-boot-actuator


    【解决方案1】:

    哈利路亚,终于找到我上面描述的问题了!

    问题是我将 Spring Boot 应用程序配置为使用 Gson 而不是默认的 Jackson json 解析器。不完全清楚原因,但使用以下代码行会导致在执行器端点显示数据时出现问题。

    implementation ("org.springframework.boot:spring-boot-starter-web") {
        exclude group: "org.springframework.boot", module: "spring-boot-starter-json"
    }
    implementation "com.google.code.gson:gson:2.8.6"
    

    下面上面描述的Bean也是没必要的!

    @Bean
    public HttpTraceRepository httpTraceRepository() {
       return new InMemoryHttpTraceRepository();
    }
    

    因此以下配置也是一个问题:

    spring:
      http:
        converters:
          preferred-json-mapper: gson
      gson:
        exclude-fields-without-expose-annotation: true
    

    最后,在删除我所有的 @Expose 注释后,它又开始完美地工作了。

    @Expose
    private String content;
    

    如果有人可以向我解释为什么会发生这种情况,或者如何配置 Gson 以与 Spring Boot Actuator 组合正常工作,我在这里倾听和理解.

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我通过删除以下行来解决

      gsonBuilder.excludeFieldsWithoutExposeAnnotation()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-27
        • 2019-05-26
        • 2022-01-06
        • 2020-02-07
        • 2018-04-10
        • 1970-01-01
        相关资源
        最近更新 更多