Spring Boot 2执行器 /health 和 /info 返回HTTP 404

huangapple go评论63阅读模式
英文:

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/healthlocalhost:8080/info访问上述端点 - 返回了HTTP 404响应。

我是否漏掉了什么?提前感谢您的帮助!

英文:

I've added dependencies in pom.xml to the brand new Spring Boot app, as described in the Spring documentation

&lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;

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: &quot;*&quot;
  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&#39;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&#39;t specify it, don&#39;t forget to include this in the URL
       exposure:
          include: &quot;*&quot;
  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.

huangapple
  • 本文由 发表于 2020年9月11日 21:05:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63847689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定