Spring Boot Actuator相当打印JSON

前端之家收集整理的这篇文章主要介绍了Spring Boot Actuator相当打印JSON前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

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

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

@H_301_5@spring: jackson: serialization: INDENT_OUTPUT: true

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

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

更新

这是我的application.yml

@H_301_5@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

@H_301_5@

这是常见的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配置

@H_301_5@factorybean">

选项2:代码配置

@H_301_5@@Configuration public class CustomWebMvcConfiguration extends WebMvcConfigurationSupport { @Override protected void extendMessageConverters( List

猜你在找的Spring相关文章