问题描述
我有一个春季批处理项目(使用Gradle)。我希望该项目与Actuator集成。
我已将此添加到gradle中
implementation "org.springframework.boot:spring-boot-starter-actuator"
在application.yaml中,我已添加
server:
port: 8083
servlet:
context-path: "/test"
现在,当我尝试在我的本地计算机上击中-http://localhost:8083/test/health
时,我会出错-
{
"timestamp": "2020-09-21T18:36:42.779+00:00","status": 404,"error": "Not Found","message": "","path": "/test/health"
}
在浏览器上运行相同的端点时,我看到此错误-
Whitelabel Error Page
This application has no explicit mapping for /error,so you are seeing this as a fallback.
Mon Sep 21 18:45:07 UTC 2020
There was an unexpected error (type=Not Found,status=404).
但是当我碰到其他端点,例如http://localhost:8083/nikhil/api/boot-appliation
时,它就起作用了!
我在哪里想念任何建议?
谢谢
解决方法
默认情况下,上下文路径为/
,执行器端点为:
/actuator/health
将上下文路径设置为/test
时,执行器端点为:
/test/actuator/health
URL的/actuator
部分来自management.endpoints.web.base-path
属性。我认为这就是您要设置的:
management:
endpoints:
web:
base-path: /actuator
因此,如果您的配置是这样的话,
server:
port: 8083
servlet:
context-path: /
management:
endpoints:
web:
base-path: "/test"
您的执行器终点为:
/test/health