Spring Boot 执行器不工作 - Whitelabel 错误页面

dev*_*ain 5 java spring spring-boot spring-boot-actuator

Spring Boot Actuator不适用于完全休息的应用程序,在浏览器上出现 Whitelabel 错误页面,并在控制台日志中出现以下错误。

org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /actuator/health
Run Code Online (Sandbox Code Playgroud)

添加了以下 Maven 依赖项。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我交叉检查,jar 文件在类路径中可用。在此输入图像描述

Spring Boot应用程序版本

<version>2.4.1</version>
Run Code Online (Sandbox Code Playgroud)

在 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
Run Code Online (Sandbox Code Playgroud)

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

http://localhost:8090/actuator/health
http://localhost:8090/actuator/
http://localhost:8090/health/
Run Code Online (Sandbox Code Playgroud)

日志

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]
Run Code Online (Sandbox Code Playgroud)

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

请建议我是否需要在我们的应用程序中添加任何其他配置。

小智 3

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