【发布时间】:2018-06-17 10:40:24
【问题描述】:
我第一次尝试实现 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
它返回我:
{"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 和 /info 有效。 事实上,当我请求 /health 时,它会返回:
{"status":"UP"}
当我要求 /info 它返回:
{"app":{"description":"Application to demonstrate Spring REST HATEOAS and Actuator","name":"Spring Sample Application","version":"1.0.0"}}
为什么所有其他端点都给了我Whitelabel 错误页面?
【问题讨论】:
-
对于初学者,请停止混合框架的版本。从
spring-boot-starter-actuator中删除<version>标记以获得正确的标记。 -
我已经介绍了这个问题,只是说我不明白为什么没有
标签就不能工作,因为它是由 Spring Initializr 自动生成的。 -
它应该可以在没有版本的情况下工作(否则你正在以错误的方式构建),如果你选择包含一个版本,则不要混合框架的版本(无论框架如何)。跨度>
标签: spring rest spring-boot endpoint spring-boot-actuator