【问题标题】:Neither Spring Boot Actuator + Hal-Browser nor DevTools workingSpring Boot Actuator + Hal-Browser 和 DevTools 都不起作用
【发布时间】:2018-03-18 15:56:32
【问题描述】:

更新:附加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 spring-boot browser hal actuator


【解决方案1】:

注意:此答案基于 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 here 的更多信息,请参阅我的更多信息。


为了便于搜索,单页上的相关文档如下:

【讨论】:

  • 我刚刚在某处看到 /actuator 在 Spring Boot 2.0 中被短暂更改为 /application -- 但从 2.0.0-RELEASE 开始,它又回到了 /actuator
【解决方案2】:
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#

【讨论】:

    【解决方案3】:

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

    management.endpoints.web.exposure.include=*  
    

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

    http://localhost:8080/actuator/
    

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

    http://localhost:8080/actuator/health
    

    需要依赖:

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

    【讨论】:

      【解决方案4】:

      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>
      

      【讨论】:

        【解决方案5】:

        你不是在“in28minutes”学习课程吗? =) 无论如何,当我学习Spring Boot for Beginners in 10 Steps 课程时,我在访问http://localhost:8080/application 时遇到了同样的问题。

        对于http://localhost:8080/browser,我得到了一个普通的json

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

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

        一些谷歌搜索把我带到了this 文章。在名为“II. Hal 浏览器”的部分中,您可以看到一个屏幕截图,其中浏览器中的链接是http://localhost:8080/browser/index.html#。如果使用这个链接,那么 Hal Browser 应该会神奇地出现。

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

        注意:上述方法适用于 Spring Boot 2.1.7 版

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-03-13
          • 1970-01-01
          • 2017-08-26
          • 1970-01-01
          • 2017-03-23
          • 2021-07-15
          • 2021-10-28
          • 1970-01-01
          相关资源
          最近更新 更多