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

Vin*_*agi 14 java spring maven spring-boot

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

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

更多细节在这里

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);
    }
}

Run Code Online (Sandbox Code Playgroud)

演示控制器.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!";
    }   
}

Run Code Online (Sandbox Code Playgroud)

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>

Run Code Online (Sandbox Code Playgroud)

小智 5

在文件application.properties (src/main/resources) 中添加以下行:

spring.devtools.livereload.enabled=true


Has*_*esh 5

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

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

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


小智 3

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

就您而言,您的TanmayTestApplication课程位于 package 中com.example.tanmay_test。因此,您的DemoControler类必须位于包内com.example.tanmay_test.xxx

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

希望这可以帮助!