英文:
Spring Boot 2 Actuator /health and /info returns HTTP 404
问题
我已经在全新的Spring Boot应用的pom.xml
文件中添加了依赖,就像Spring文档中描述的那样:
<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>
并且在application.yml
文件中添加了以下属性,以便只暴露/health
和/info
端点:
management:
endpoints:
web:
exposure:
include:
- info
- health
jmx:
exposure:
exclude: "*"
endpoint:
info:
enabled: true
health:
enabled: true
但是在运行应用程序后,无法通过localhost:8080/health
和localhost:8080/info
访问上述端点 - 返回了HTTP 404响应。
我是否漏掉了什么?提前感谢您的帮助!
英文:
I've added dependencies in pom.xml
to the brand new Spring Boot app, as described in the Spring documentation
<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>
and added the following properties to the application.yml
in order to just expose /health
and /info
endpoints
management:
endpoints:
web:
exposure:
include:
- info
- health
jmx:
exposure:
exclude: "*"
endpoint:
info:
enabled: true
health:
enabled: true
but can't reach the mentioned endpoints on running app via localhost:8080/health
and localhost:8080/info
- there is HTTP 404 response.
Am I missing something? Thank you for your help in advance!
答案1
得分: 4
有两种可能的配置可以更改执行器的 /health 和 /info 端点:
首先是 spring boot mvc 服务器,假设您的配置如下:
server:
port: 8080
servlet:
context-path: /test
其次是 执行器管理服务器:
management:
server:
#port: #不要更改它,这样执行器的端口将与上述 server.port 相同
endpoints:
web:
base-path: /actuator #对于 spring boot 2.x,默认值是 /actuator,即使您不指定它,也不要忘记在 URL 中包含此部分
exposure:
include: "*"
endpoint:
health:
show-details: always
因此,访问执行器的正确 URL 应为:
http://localhost:8080/test/actuator/info
http://localhost:8080/test/actuator/health
总体上,访问执行器端点的 URL 模式应为:
http://localhost:{server.port}/{server.servlet.context-path}/{management.endpoints.web.base-path}/**
您可以将您的配置与此示例进行比较,以查看是什么导致了 404 错误。
英文:
There are two possible configurations that could change Actuator /health and /info endpoints:
First, the spring boot mvc server, assume you have it like this:
server:
port: 8080
servlet:
context-path: /test
Second, the Actuator management server:
management:
server:
#port: #don't change it, then the port for actuator will be the same as server.port above
endpoints:
web:
base-path: /actuator #the default value for sring boot 2.x is /actuator, even you don't specify it, don't forget to include this in the URL
exposure:
include: "*"
endpoint:
health:
show-details: always
So the right URLs to access Actuator should be :
http://localhost:8080/test/actuator/info
http://localhost:8080/test/actuator/health
On the whole, the URL pattern to visit Actuator endpoints should be:
http://localhost:{server.port}/{server.servlet.context-path}/{management.endpoints.web.base-path}/**
You can compare your configurations with this example to see what's causing the 404 error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论