繁体   English   中英

Spring Boot 2 Actuator /health 和 /info 返回 HTTP 404

[英]Spring Boot 2 Actuator /health and /info returns HTTP 404

我已将pom.xml中的依赖项添加到全新的 Spring Boot 应用程序中,如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/healthlocalhost:8080/info在运行应用程序时到达上述端点 - 有 HTTP 404 响应。

我错过了什么吗? 提前谢谢你的帮助!

有两种可能的配置可以更改 Actuator /health 和 /info 端点:

首先, spring boot mvc server ,假设你有这样的:

server:
   port: 8080
   servlet:
      context-path: /test

二、 Actuator管理服务器

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

所以访问 Actuator 的正确 URL 应该是:

http://localhost:8080/test/actuator/info

http://localhost:8080/test/actuator/health

总的来说,访问 Actuator 端点的 URL 模式应该是:

http://localhost:{server.port}/{server.servlet.context-path}/{management.endpoints.web.base-path}/**

您可以将您的配置与此示例进行比较,以查看导致 404 错误的原因。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM