java 如何使用 STS 运行 Spring Boot 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42056067/
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
How to run Spring boot application with STS
提问by Leandro Borges Ferreira
I am starting to learn microservices with Spring Boot. I go to root of my project and run the command:
我开始用 Spring Boot 学习微服务。我转到我的项目的根目录并运行命令:
mvn spring-boot:run
It works just fine and I can use my endpoints in localhost:8080/[path]. But when I try to run my project from the IDE using Run as -> Spring Boot App. I get this error:
它工作得很好,我可以在 localhost:8080/[path] 中使用我的端点。但是当我尝试使用 Run as -> Spring Boot App 从 IDE 运行我的项目时。我收到此错误:
Error: Could not find or load main class
I could just use command line, but I really would like to know why I getting this error with the IDE. So, what I have to do to run my project from the IDE?
我可以只使用命令行,但我真的很想知道为什么我在 IDE 中遇到这个错误。那么,我必须做什么才能从 IDE 运行我的项目?
Edit 1:
编辑1:
There is my Main Class:
有我的主班:
package br.com.leandroborgesferreira.microlearn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MicroLearnApplication {
public static void main(String[] args) {
SpringApplication.run(MicroLearnApplication.class, args);
}
}
Any help is appreciated!
任何帮助表示赞赏!
回答by Solorad
I had the same problem. In my case problem was in default maven configurations in Intellij Idea. Go to settings and Settings -> Build Execution, Deployment -> Maven. Set maven home directory to correct one, not bundled with IJ IDEA. Right Click the project -> Maven -> Reimport Then Re-run the project. Hope it work for you too.
我有同样的问题。就我而言,问题出在 Intellij Idea 中的默认 Maven 配置中。转到设置和设置 -> 构建执行、部署 -> Maven。将 maven 主目录设置为更正一个,不与 IJ IDEA 捆绑。右键项目 -> Maven -> Reimport 然后重新运行项目。希望它也对你有用。
Also, please check Working directory
in 'Run Configuration'. It should be something like "MODULE_DIR"
另外,请检查Working directory
“运行配置”。它应该类似于“MODULE_DIR”
回答by pramod singh
just right click within main class
and run as > spring boot/java application
只需右键单击main class
其中run as > spring boot/java application