Spring Boot Actuator 不工作 - 白标错误页面

问题描述

Spring Boot Actuator 不适用于完整的应用程序,在浏览器上出现白标错误页面,在控制台日志中出现以下错误

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 文件

enter image description here

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 访问 Actuator

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]

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

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

解决方法

如果在 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