Spring Boot因LSP而出现问题(无法从进程中刷新实时数据…)

huangapple go评论103阅读模式
英文:

Spring Boot Problem because of LSP (failed to refresh live data from process ...)

问题

以下是翻译好的内容:

我刚开始使用 Spring Boot。我新建的项目无法成功运行。
我想用“以 Spring Boot App 方式运行”来运行 Spring Boot 应用,但我遇到了和 @Vinay Vaishnav 相同的错误。我尝试了回复中提到的所有方法。

我最初的错误是:无法从进程刷新实时数据...

更改前的 LSP 错误

在那之后,我在 pom.xml 中添加了以下依赖:

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

由于添加了这个依赖,错误消失了,但是然后我遇到了 404 错误。

白标签错误

我还在 applicationProperties 中添加了 livereload devtools。不管是否添加了这行,都没有影响。

现在是我的代码:

AppConfiguration.java:

package com.example.demo;

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

public class AppConfiguration {

    @RequestMapping("/hello") 
    public String hello() {
        return "Hello World";
    }
}

applicationProperties:

spring.devtools.livereload.enabled=true
server.port=8081

HelloWorldApplication.java:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class HelloWorldApplication {

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

我的版本信息:

  • Apache Maven 3.6.3
  • Spring Boot 2.2.6
  • JDK 13.0.2
英文:

I just began to use spring boot. My new created project doesn´t work succesfully.
I want to run the spring boot app with "run as Spring Boot App" but I´ve got the same error as @Vinay Vaishnav. I´ve tried everything covered in the replies.

My first error was: Failed to refresh live data from process ...

LSP ERROR Before Changes

After that I included following dependency to the pom.xml:

&lt;dependency&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;

Because of the added dependency the error is gone but then i´ve got 404

WhiteLabel Error

I also added the livereload devtools in the applicationProperties. It doesn´t matter if this line is added or not.

That´s my code for now:

AppConfiguration.java:

package com.example.demo;

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

public class AppConfiguration {

	@RequestMapping(&quot;/hello&quot;) 
	public String hello() {
		return 	&quot;Hello World&quot;;
	}
}

applicationProperties:

spring.devtools.livereload.enabled=true
server.port=8081

HelloWorldApplication.java:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;


@RestController
@SpringBootApplication
public class HelloWorldApplication {

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

My versions:

  • Apache Maven 3.6.3
  • Spring Boot 2.2.6
  • JDK 13.0.2

答案1

得分: 1

更好的做法是在STS首选项中禁用进程跟踪,而不是添加依赖项,如果项目实际上没有使用它。

英文:

It's better to disable the process tracking in STS preferences, instead of adding the dependency, if the project not actually uses it.

Spring Boot因LSP而出现问题(无法从进程中刷新实时数据…)

答案2

得分: 0

你在混淆如何编写你的类。

首先,@RestController 必须放在一个将控制请求的类中。(在你的情况下,应放在 AppConfiguration 中)

通过这个变更,应该可以正常工作。

而且,你应该将你的类名更改为 AppController。(只是为了更符合类的功能)

英文:

You are confusing how to write down your classes.

First, @RestController must be in a class that is going to control the requests. (In your case it should go in AppConfiguration)

With this change it should work.

And you should change the name of your class to AppController. (Just to be more consistent with what the class does)

huangapple
  • 本文由 发表于 2020年4月8日 20:05:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/61100278.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定