在我设置的 Spring Boot App (2.0.0.M7) application.properties 中
management.endpoint.metrics.enabled=true
然而,当我打
localhost:8080/actuator/metrics
我得到 404。
解决办法是什么?
请您参考如下方法:
我想用更多信息来增强 OP 的答案,因为我在最终偶然发现这个解决方案之前有点挣扎,而且似乎对 Spring Boot 2 执行器行为的变化有很多困惑
什么没变
您需要包含对 spring-boot-starter-actuator 的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
如果要通过 HTTP 访问执行器端点,还需要添加对 spring-boot-starter-web 的依赖
所以你的 pom 依赖项将如下所示
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
Spring Boot 2 中引入的更改
/health
, /metrics
等是不再在默认根上下文中可用。从现在开始,它们可以在http://{host}:{port}/actuator
.此外,您的应用程序的所有其他端点是否以其他上下文开头也没有关系,例如
/hello
-- 执行器可在 /actuator
获得而不是在 /hello/actuator
. /actuator
的回复端点默认为 HATEOAS启用。在 Spring Boot 2 之前,只有这种情况 if HATEOAS is on the classpath and explicitly enabled在 application.yml
默认:
/health
和 /info
无论您的应用程序中是否存在和配置 Spring Security,端点都是公开的。 /shutdown
已启用(尽管只有 /health
和 /info
暴露)management.endpoints.web.exposure.include=*
来实现。至 application.properties
.如果您使用 yml-configurations,请不要忘记引用通配符。 endpoints.xyz
开头的旧属性不推荐使用以 management.xyz
开头的属性如需完整文档,请参阅 official doc还有 migration guide