英文:
Spring Boot Problem because of LSP (failed to refresh live data from process ...)
问题
以下是翻译好的内容:
我刚开始使用 Spring Boot。我新建的项目无法成功运行。
我想用“以 Spring Boot App 方式运行”来运行 Spring Boot 应用,但我遇到了和 @Vinay Vaishnav 相同的错误。我尝试了回复中提到的所有方法。
我最初的错误是:无法从进程刷新实时数据...
在那之后,我在 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 ...
After that I included following dependency to the pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Because of the added dependency the error is gone but then i´ve got 404
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("/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);
}
}
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.
答案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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论