3

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]

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

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

4

3 回答 3

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

于 2021-04-18T19:37:37.287 回答
1

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

右键单击 pom.xml 文件并选择 Maven->Reload project,解决了它。

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

于 2021-09-12T13:50:16.293 回答
0

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

转到File->“使缓存无效”。

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

于 2021-10-18T02:02:04.947 回答