【问题标题】:Spring Boot Actuator not working- Whitelabel Error PageSpring Boot Actuator 不工作 - Whitelabel 错误页面
【发布时间】:2021-02-20 07:30:05
【问题描述】:

Spring Boot Actuator 不适用于 rest-full 应用程序,在浏览器上出现 Whitelabel 错误页面,在控制台日志中出现以下错误。

org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /actuator/health

在maven依赖下添加。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

我交叉检查了,jar 文件在类路径中可用。

Spring Boot 应用版本

<version>2.4.1</version>

在 application.properties 文件中添加属性

management.endpoints.enabled-by-default=true
management.endpoint.info.enabled=true
management.security.enabled=false
management.endpoints.web.exposure.include=*
spring.mvc.throw-exception-if-no-handler-found=true

无法使用以下 URL 访问执行器

http://localhost:8090/actuator/health
http://localhost:8090/actuator/
http://localhost:8090/health/

日志

WARN IN-WKS-435 [nio-8090-exec-1] o.s.w.s.PageNotFound                     : No mapping for GET /actuator/health
WARN IN-WKS-435 [nio-8090-exec-1] o.s.w.s.PageNotFound                     : No handler found for GET /actuator/health
WARN IN-WKS-435 [nio-8090-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /actuator/health]

注意:除此之外,整个应用程序运行良好。

如果我需要在我们的应用程序中添加任何其他配置,请提出建议。

【问题讨论】:

  • 请检查以下几点: 1. 属性中是否有management.server.port 配置值?它将更改执行器可访问的端口 2. 调用时的应用程序日志 - 查看是否没有错误 3. 在应用程序启动时,请检查日志行 Exposing 14 endpoint(s) beneath base path '/actuator' - 仔细检查这些端点是否实际暴露。希望这有助于找出根本原因
  • @Daniel 感谢您的及时响应,在启动时我看不到在基本路径“/执行器”下暴露 14 个端点。我刚刚编辑了帖子并添加了日志。
  • 你能在外部库中看到执行器吗?也许不知何故它没有正确添加@VivekJain
  • dextertron 我已验证,在类路径中可用。

标签: java spring spring-boot actuator


【解决方案1】:

如果在 IDE(IntelliJ 或 Eclipse)中运行,则无法获取 Spring Boot Actuators 端点。

我尝试在 cmd 上使用以下命令(IDE 外部)运行 jar,它对我有用。

c:\workspace\demo\target\java -jar demo-spring-boot-project.jar

我可以访问以下网址

http://localhost:8090/actuator/health

【讨论】:

    【解决方案2】:

    在通过 InteliJ IDEA 运行应用程序时也遇到了这种情况。 原来我添加了 spring-boot-starter-actuator 依赖,但没有告诉 Maven 重新加载项目。

    在pom.xml文件上右击选择Maven->Reload project,解决了。

    *在这种情况下,我看到 jar 文件存在于您的类路径中,因此您的问题与我的不同。 留下此评论,以便对其他人有所帮助。

    【讨论】:

      【解决方案3】:

      我在通过 IntelliJ IDE 运行项目时遇到了同样的问题。 我在 IntelliJ IDE 中执行 Invalidate Cache &amp; Restart 后解决了。

      转到File -> ``无效缓存`。

      出现“无效缓存”对话框。可以根据自己的项目进行选择。

      【讨论】:

        猜你喜欢
        • 2017-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-10
        • 2018-06-09
        • 2018-04-19
        • 2017-10-06
        相关资源
        最近更新 更多