【问题标题】:Spring actuator giving 404 Not found error even after setting server.servlet.contextPath即使在设置 server.servlet.contextPath 之后,弹簧执行器也会给出 404 Not found 错误
【发布时间】:2020-09-21 18:39:14
【问题描述】:

我有一个春季批处理项目(使用 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 等其他端点时,它可以工作!

有什么我遗漏的建议吗?

谢谢

【问题讨论】:

    标签: java spring spring-boot gradle spring-boot-actuator


    【解决方案1】:

    默认情况下,上下文路径是/,执行器端点是:

    /actuator/health
    

    上下文路径设置为/test,执行器端点为:

    /test/actuator/health
    

    网址的/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
    

    【讨论】:

      猜你喜欢
      • 2021-08-11
      • 2021-12-18
      • 2013-03-10
      • 2015-08-31
      • 2016-08-30
      • 2012-03-09
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      相关资源
      最近更新 更多