Spring Boot Actuator + Hal-Browser 和 DevTools 都无法正常工作



更新:附加pom.xmlapplication.property以及更多错误/警告消息。

嗨,我对Spring Boot很陌生,只是在Udemy上上了一些课程。

在完成一个类的过程中,我通过 spring.io 创建了一个入门项目,并添加了执行器和 Hal 浏览器依赖项,包括开发工具。

刚刚运行了我的应用程序并尝试去localhost:8080/application&/browser,但我得到了 404。

我做错了什么?

我写了一个简单的bean,它返回一个硬编码值,然后打印出来,我更改了该值以测试开发工具,但它没有重新启动资源,我不得不杀死并重新启动应用程序以反映新的更改。

我怎样才能检查什么问题?

如果需要,我可以提供控制台抓取。

请帮忙。

更新:我不知道以下内容的意义,所以把它放在这里。

在 XML 编辑器中,hal 在悬停时带有红色下划线,并带有以下消息:

托管版本是 3.0.5.RELEASE 工件在 org.springframework.data:spring-data-releasetrain:Kay-SR5 中管理

在 XML 编辑器中,devtools 在悬停时带有红色下划线,并带有以下消息:

托管版本是 2.0.0.RELEASE 工件在 org.springframework.boot:spring-boot-dependencies:2.0.0.RELEASE 中管理。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myoxigen.training.springboot</groupId>
<artifactId>library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>library</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

application.properties文件:

logging.level.org.springframework = DEBUG
management.security.enabled=false

注意:这个答案是基于 Spring Boot 2(路径和属性已从版本 1 更改)。

你的pom.xml对我来说很好。 要使"HAL浏览器"与执行器一起使用,您应该具有启动器:webactuatorRest Repositories HAL Browser。 我推荐 Spring Initializr 作为构建初始有效项目结构的好方法。

执行器的默认路径为/actuator。 例如,健康处于/actuator/health.

要在 HAL 浏览器中查看执行器端点,请转至/browser/index.html#/actuator

您可以通过设置以下内容来更改application.properties中的执行器路径。

management.endpoints.web.base-path=/actuator

要运行服务器,请使用以下控制台命令:

./mvnw clean spring-boot:run

如果项目中有DevTools,则对类路径中的文件的更改将重新启动服务器。 请参阅我有关如何利用 DevTools 的进一步评论 此处.


以下是单个页面上的相关文档,以便于搜索:

  • https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle
  • https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle
Add this Dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.5.RELEASE</version>
</dependency>`enter code here`
And then go to link:
http://localhost:8080/browser/index.html#

Spring Boot 2.2 应用程序应该使用 spring-data-rest-hal-explorer 而不是spring-data-rest-hal-browser

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>

要启用执行器,请将其添加到属性文件 (application.properties) 中

management.endpoints.web.exposure.include=*  

重新启动 Spring 引导应用程序并使用以下命令访问执行器端点:

http://localhost:8080/actuator/

还可以使用以下方法监视应用程序的运行状况:

http://localhost:8080/actuator/health

所需的依赖项:

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

你不是在"in28分钟"学习一门课程吗? =) 无论如何,当我学习 10 步初学者春季引导课程时,我在访问http://localhost:8080/application时遇到了同样的问题。

http://localhost:8080/browser我得到了一个简单的json

{"cause":null,"message":"Fragment must not be empty"}

pom.xml,我与您概述的依赖项相同。

一些谷歌搜索把我带到了这篇文章。在名为"II.哈尔浏览器"您可以看到屏幕截图,其中浏览器中的链接http://localhost:8080/browser/index.html#。如果使用此链接,那么哈尔浏览器应该神奇地出现。

所以/index.html#是你唯一错过的拼图。

注意:上述方法适用于 Spring 引导版本 2.1.7

编辑:尽管哈尔浏览器本身可以使用上述方法,但它仍然没有显示执行器端点。DevTools也不适合我。

最新更新