加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Spring Boot Actuator相当打印JSON

发布时间:2020-12-15 01:24:01 所属栏目:大数据 来源:网络整理
导读:在我的Spring Boot 1.3.3.RELEASE应用程序中,Actuator的Health端点返回以下JSON: {"status":"UP","diskSpace":{"status":"UP","total":120031539200,"free":109277069312,"threshold":10485760}} 我想要返回漂亮的打印JSON而不是单个字符串. 我在我的applic

在我的Spring Boot 1.3.3.RELEASE应用程序中,Actuator的Health端点返回以下JSON:

{"status":"UP","diskSpace":{"status":"UP","total":120031539200,"free":109277069312,"threshold":10485760}}

我想要返回漂亮的打印JSON而不是单个字符串.

我在我的application.yml中添加了以下配置:

spring:
  jackson:
    serialization:
      INDENT_OUTPUT: true

但输出仍然返回相同的单个字符串.

如何正确配置我的应用程序以返回漂亮的JSON?

更新

这是我的application.yml

server:
  port: @server.port@
  contextPath: /dashboard

management:
  contextPath: /actuator 

spring:
  jackson:
    serialization:
      INDENT_OUTPUT: true
  jmx:
    enabled: false
  aop:
    proxy-target-class: @spring.aop.proxy-target-class@
  security:
    bcryptPasswordEncoder:
      strength: @spring.security.bcryptPasswordEncoder.strength@
  datasource:
    driverClassName: @spring.datasource.driverClassName@
    url: @spring.datasource.url@
    username: @spring.datasource.username@
    password: @spring.datasource.password@
  jpa:
    database: @spring.jpa.database@
    database-platform: @spring.jpa.database-platform@
    hibernate.ddl-auto: @spring.jpa.hibernate.ddl-auto@
    show-sql: @spring.jpa.show-sql@

ok:
  client:
    clientSecret: @ok.client.clientSecret@
    clientPublicKey: @ok.client.clientPublicKey@

这是父pom.xml


这是常见的pom.xml


这个主要的pom.xml


Chrome屏幕截图:

enter image description here

最佳答案
尽管已经提到了所有很好的答案,但我希望它们能为我工作,但是在spring-boot-starter-1.3.3.RELEASE中,唯一让我的JSON打印到漂亮的配置是Jenky’s答案:Jackson PrettyPrint for Spring 4

为方便起见,我正在从那篇文章中复制两个可能的解决方案,XML配置或代码配置.

选项1:XML配置


选项2:代码配置

@Configuration
public class CustomWebMvcConfiguration extends WebMvcConfigurationSupport {

    @Override
    protected void extendMessageConverters( List

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读