Java 基本的 Spring Boot 应用程序不起作用,显示:无法从进程 xxxx 刷新实时数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/60010007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:21:09  来源:igfitidea点击:

Basic spring boot app not working, showing: Failed to refresh live data from process xxxx

javaspringspring-bootmaven

提问by Vinay Vaishnav

I am beginner for spring boot. I initialized a new project and tried to run it but it does not work successfully. WHen I run this as spring boot application, it starts execution. In bottom compiler/status bar, it shows processing and retrying. it goes upto 10 times and throw the following error:

我是弹簧靴的初学者。我初始化了一个新项目并尝试运行它,但它无法成功运行。当我将它作为 Spring Boot 应用程序运行时,它开始执行。在底部编译器/状态栏中,它显示正在处理和重试。它最多运行 10 次并抛出以下错误:

Failed to refresh live data from process xxxx

无法从进程 xxxx 刷新实时数据

More detail here

更多细节在这里

TanmayTestApplication.java

TanmayTestApplication.java

package com.example.tanmay_test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TanmayTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(TanmayTestApplication.class, args);
    }
}

DemoControler.java

演示控制器.java

package com.example.cntr;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class DemoControler {

    @RequestMapping(path = "/index")
    public String index() {
        return "By Tanmay!";
    }   
}

pom.xml

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>tanmay_test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>tanmay_test</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <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-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

回答by Hasathon

I have faced the same problem but managed to solve it. The controller class has to be in the "child package" relative to the TestApplicationclass.

我遇到了同样的问题,但设法解决了它。控制器类必须在相对于TestApplication该类的“子包”中。

In your case, your TanmayTestApplicationclass is in the package com.example.tanmay_test. Therefore, your DemoControlerclass must be inside the package com.example.tanmay_test.xxx.

在您的情况下,您的TanmayTestApplication课程在包中com.example.tanmay_test。因此,您的DemoControler类必须在 package 内com.example.tanmay_test.xxx

**Note that xxx can be anything but extends from package com.example.tanmay_test. For example, package com.example.tanmay_test.web.

**请注意, xxx 可以是任何东西,但不能从 package 扩展com.example.tanmay_test。例如,包com.example.tanmay_test.web.

Hope this helps!

希望这可以帮助!

回答by roundAbout

It is simply saying that you didn't enable LiveReload.

这只是说您没有启用LiveReload

回答by Petter

Add this line in your file application.properties(src/main/resources):

在您的文件application.properties(src/main/resources) 中添加这一行:

spring.devtools.livereload.enabled=true

spring.devtools.livereload.enabled=true

回答by Martin Theiss

Live data is collected with the help of Spring Actuator.

在 Spring Actuator 的帮助下收集实时数据。

You need to include the following dependency in your pom.xml

您需要在 pom.xml 中包含以下依赖项

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

See https://github.com/spring-projects/sts4/wiki/Live-Application-Information#application-requirements-for-spring-boot-projectsfor reference.

请参阅https://github.com/spring-projects/sts4/wiki/Live-Application-Information#application-requirements-for-spring-boot-projects以供参考。

回答by Hashan Mahesh

I had the same problem in STS, and tried different things to resolve it. The following dependency for spring actuator makes that problem disappear, but however the main point of spring actuator provides more features than this. To learn more, click https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html

我在 STS 中遇到了同样的问题,并尝试了不同的方法来解决它。弹簧执行器的以下依赖性使该问题消失,但是弹簧执行器的要点提供了比这更多的功能。要了解更多信息,请单击https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html

The dependency should be added to your pom.xml file

应该将依赖项添加到您的 pom.xml 文件中

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