spring boot 中使用 actuator 404的问题
代码路径:https://gitee.com/WChengHe/tensquare_parent.git
背景:在自己写demo的时候,使用actuator的时候,查看一些端口时报404.
下图为目前启用的服务:
以base服务为例,使用actuator.
按照actuator的使用方法,项目中添加actuator的依赖
pom文件依赖:
<!-- add by WanChengHe 20190517 增加Actuator依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
测试端点:/infp 是正常的,
测试端点: /beans 报404
经过查阅资料,发现问题原因为:2.0的大部分的端点都屏蔽了(/info、/health 没屏蔽)。
解决方案: 在SpringBoot的application.yml配置文件中加入配置暴露所有端点。
management:
endpoints:
web:
exposure:
include: "*" # * 在yaml 文件属于关键字,所以需要加引号
添加配置后测试beans端口:
附录:
1.X 的时候属性:
HTTP 方法 | 路径 | 描述 |
---|---|---|
GET | /autoconfig | 提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过 |
GET | /configprops | 描述配置属性(包含默认值)如何注入Bean |
GET | /beans | 描述应用程序上下文里全部的Bean,以及它们的关系 |
GET | /dump | 获取线程活动的快照 |
GET | /env | 获取全部环境属性 |
GET | /env/{name} | 根据名称获取特定的环境属性值 |
GET | /health | 报告应用程序的健康指标,这些值由HealthIndicator的实现类提供 |
GET | /info | 获取应用程序的定制信息,这些信息由info打头的属性提供 |
GET | /mappings | 描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系 |
GET | /metrics | 报告各种应用程序度量信息,比如内存用量和HTTP请求计数 |
GET | /metrics/{name} | 报告指定名称的应用程序度量值 |
POST | /shutdown | 关闭应用程序,要求endpoints.shutdown.enabled设置为true |
GET | /trace | 提供基本的HTTP请求跟踪信息(时间戳、HTTP头等) |
2.0 部分更改:
1.x 端点 | 2.0 端点(改变) |
---|---|
/actuator |
不再可用。 但是,在 management.endpoints.web.base-path 的根目录中有一个映射,它提供了到所有暴露端点的链接。 |
/auditevents |
该after 参数不再需要 |
/autoconfig |
重命名为 /conditions
|
/docs |
不再可用 |
/health |
现在有一个 management.endpoint.health.show-details 选项 never , always , when-authenticated ,而不是依靠 sensitive 标志来确定 health 端点是否必须显示全部细节。 默认情况下,/actuator/health 公开并且不显示细节。 |
/trace |
重命名为 /httptrace
|
默认端点 path 前面多了一级 /actuator
。