Spring-引导执行器:只有一些端点工作
Spring-boot actuator: only some endpoints work
我第一次尝试实现 spring-boot 执行器,但我注意到:
- 只有指定版本才有效,否则无效;
- 在 /actuator 端点响应声明的那些端点中,只有少数端点有效。
这是我在 pom.xml
中插入的依赖项
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-docs</artifactId>
</dependency>
...
</dependencies>
这是我的 application.properties:
#info for Spring Boot Actuator
info.app.name=Spring Sample Application
info.app.description=Application to demonstrate Spring REST HATEOAS and Actuator
info.app.version=1.0.0
当我发出此 http 请求时:
http://localhost:8080/actuator
它returns我:
{"links":[{"rel":"self","href":"http://localhost:8080/actuator"},{"rel":"loggers","href":"http://localhost:8080/loggers"},{"rel":"env","href":"http://localhost:8080/env"},{"rel":"info","href":"http://localhost:8080/info"},{"rel":"heapdump","href":"http://localhost:8080/heapdump"},{"rel":"mappings","href":"http://localhost:8080/mappings"},{"rel":"metrics","href":"http://localhost:8080/metrics"},{"rel":"configprops","href":"http://localhost:8080/configprops"},{"rel":"autoconfig","href":"http://localhost:8080/autoconfig"},{"rel":"beans","href":"http://localhost:8080/beans"},{"rel":"auditevents","href":"http://localhost:8080/auditevents"},{"rel":"trace","href":"http://localhost:8080/trace"},{"rel":"health","href":"http://localhost:8080/health"},{"rel":"dump","href":"http://localhost:8080/dump"},{"rel":"docs","href":"http://localhost:8080/docs"}]}
在这些链接中,只有 /health and /info 似乎有效。
事实上,当我要求 /health 它 returns:
{"status":"UP"}
当我请求 /info 时,它返回:
{"app":{"description":"Application to demonstrate Spring REST HATEOAS and Actuator","name":"Spring Sample Application","version":"1.0.0"}}
为什么所有其他端点都会给我 Whitelabel 错误页面?
您尝试其他端点时是否尝试查看日志。它说
Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.
我想这是不言自明的。至少配置基本身份验证或将上述 属性 设置为 false
.
您看到的 Whitelabel 错误页面还显示
There was an unexpected error (type=Unauthorized, status=401).
Here 是与此相关的文档的 link。
在我的例子中,我收到了 404 Whitelabel Error Page 因为只有 /actuator/health
和 /actuator/info
默认情况下仅启用端点(如 Spring Boot Actuator documentation 中所述)
为了启用其他端点,我最终将此配置添加到我的 application.yml
:
management:
endpoints:
web:
exposure:
include: info, health, loggers, logfile, configprops
我在 Baeldung 找到了一个帖子,上面写着
Unlike in previous versions, Actuator comes with most endpoints disabled. (Link)
所以将 management.endpoints.web.exposure.include=*.
添加到您的 application.properties
。
我第一次尝试实现 spring-boot 执行器,但我注意到:
- 只有指定版本才有效,否则无效;
- 在 /actuator 端点响应声明的那些端点中,只有少数端点有效。
这是我在 pom.xml
中插入的依赖项<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-docs</artifactId>
</dependency>
...
</dependencies>
这是我的 application.properties:
#info for Spring Boot Actuator
info.app.name=Spring Sample Application
info.app.description=Application to demonstrate Spring REST HATEOAS and Actuator
info.app.version=1.0.0
当我发出此 http 请求时:
http://localhost:8080/actuator
它returns我:
{"links":[{"rel":"self","href":"http://localhost:8080/actuator"},{"rel":"loggers","href":"http://localhost:8080/loggers"},{"rel":"env","href":"http://localhost:8080/env"},{"rel":"info","href":"http://localhost:8080/info"},{"rel":"heapdump","href":"http://localhost:8080/heapdump"},{"rel":"mappings","href":"http://localhost:8080/mappings"},{"rel":"metrics","href":"http://localhost:8080/metrics"},{"rel":"configprops","href":"http://localhost:8080/configprops"},{"rel":"autoconfig","href":"http://localhost:8080/autoconfig"},{"rel":"beans","href":"http://localhost:8080/beans"},{"rel":"auditevents","href":"http://localhost:8080/auditevents"},{"rel":"trace","href":"http://localhost:8080/trace"},{"rel":"health","href":"http://localhost:8080/health"},{"rel":"dump","href":"http://localhost:8080/dump"},{"rel":"docs","href":"http://localhost:8080/docs"}]}
在这些链接中,只有 /health and /info 似乎有效。 事实上,当我要求 /health 它 returns:
{"status":"UP"}
当我请求 /info 时,它返回:
{"app":{"description":"Application to demonstrate Spring REST HATEOAS and Actuator","name":"Spring Sample Application","version":"1.0.0"}}
为什么所有其他端点都会给我 Whitelabel 错误页面?
您尝试其他端点时是否尝试查看日志。它说
Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.
我想这是不言自明的。至少配置基本身份验证或将上述 属性 设置为 false
.
您看到的 Whitelabel 错误页面还显示
There was an unexpected error (type=Unauthorized, status=401).
Here 是与此相关的文档的 link。
在我的例子中,我收到了 404 Whitelabel Error Page 因为只有 /actuator/health
和 /actuator/info
默认情况下仅启用端点(如 Spring Boot Actuator documentation 中所述)
为了启用其他端点,我最终将此配置添加到我的 application.yml
:
management:
endpoints:
web:
exposure:
include: info, health, loggers, logfile, configprops
我在 Baeldung 找到了一个帖子,上面写着
Unlike in previous versions, Actuator comes with most endpoints disabled. (Link)
所以将 management.endpoints.web.exposure.include=*.
添加到您的 application.properties
。