简体   繁体   English

Spring 执行器即使在设置 server.servlet.contextPath 后也给出 404 Not found 错误

[英]Spring actuator giving 404 Not found error even after setting server.servlet.contextPath

I have a spring batch project (Using Gradle).我有一个 spring 批处理项目(使用 Gradle)。 I want to the project to be integrated with Actuator.我希望该项目与 Actuator 集成。

I have added this to import to gradle implementation "org.springframework.boot:spring-boot-starter-actuator"我已经添加了这个以导入到 gradle implementation "org.springframework.boot:spring-boot-starter-actuator"

In application.yaml, I have added在 application.yaml 中,我添加了

server:
  port: 8083
  servlet:
    context-path: "/test"

Now, when I try to hit - http://localhost:8083/test/health on my local, I get error -现在,当我尝试在本地访问 - http://localhost:8083/test/health时,出现错误 -

{
    "timestamp": "2020-09-21T18:36:42.779+00:00",
    "status": 404,
    "error": "Not Found",
    "message": "",
    "path": "/test/health"
}

On running the same endpoint on browser, I see this error-在浏览器上运行相同的端点时,我看到这个错误 -

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).

But when I hit other endpoints like http://localhost:8083/nikhil/api/boot-appliation , it works!但是当我点击其他端点时,比如http://localhost:8083/nikhil/api/boot-appliation ,它起作用了!

Any suggestions where I am missing?我缺少的任何建议?

Thanks谢谢

By default the context-path is / , and the actuator endpoint is:默认情况下,上下文路径是/ ,执行器端点是:

/actuator/health

With the context-path set to /test , the actuator endpoint is:上下文路径设置为/test时,执行器端点为:

/test/actuator/health

The /actuator portion of the url is from management.endpoints.web.base-path property. url 的/actuator部分来自management.endpoints.web.base-path属性。 I think this is what you meant to set:我认为这就是您要设置的内容:

management:
  endpoints:
    web:
      base-path: /actuator

So, all together, if your configuration is this:所以,总的来说,如果你的配置是这样的:

server:
  port: 8083
  servlet:
    context-path: /
management:
  endpoints:
    web:
      base-path: "/test"

Your actuator endpoint will be:您的执行器端点将是:

/test/health

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用大写字母 server.servlet.contextPath 值点击 URL 时未加载字符串引导应用程序 - String Boot application is not loading when hitting URL with capital letter server.servlet.contextPath value Servlet 404错误-即使在更改服务器位置之后 - Servlet 404 error - even after changing server location Spring-mvc Dispatcher Servlet映射给出了404错误 - Spring-mvc Dispatcher Servlet mapping giving 404 error Spring CSRF:即使在设置请求标头之后,Ajax也会产生403错误 - Spring CSRF: Ajax giving 403 error even after setting request headers 即使遵循设置说明,intellij tomcat服务器也会给出404 - intellij tomcat server giving 404 even after following setup instructions Spring 当使用“management.server.port”属性而不是弃用的“management.port”时,启动 MockMvc 测试为执行器端点提供 404 - Spring Boot MockMvc test giving 404 for actuator endpoint when using the "management.server.port" property instead of the deprecated "management.port" Tomcat使用Spring给出404错误? - Tomcat giving 404 error with Spring? 用于自定义Servlet的Spring Boot Actuator - Spring Boot Actuator for custom Servlet 找不到404本地主机:8080 /执行器 - 404 Not Found for localhost:8080/actuator 部署 java web 应用程序后出现 404– 内部服务器错误 - After deploying java web application giving 404– Internal Server Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM