问题描述:application.yaml中的info失效问题解决
配置actuator如下
management: endpoints: web: exposure: include: "*" endpoint: health: show-details: always info: description: spring boot actuator description1: spring boot actuator description2: spring boot actuator
运行访问:http://localhost:8001/actuator/info
浏览器结果如下:
与预期结果(返回相应的JSON字符串)不符
查找文章发现,还有另外一种设置info的方法,通过实现 InfoContributor
package com.liu.au_info; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; @Component public class MyInfo implements InfoContributor { @Override public void contribute(Info.Builder builder) { Map<String, String> info = new HashMap<>(); info.put("name", "航歌"); info.put("email", "[email protected]"); builder.withDetail("author", info); } }
访问同样网址结果:
结论:当yml配置中的文件失效时,可以尝试编写他的实现类,来实现功能。
至于为何在yml的配置中,info字段会失效,我就不知道啦,等我找到了,再更!
关于详细的actuator相关说明,参看这篇Spring boot监控——Actuator 详解
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。