简体   繁体   中英

How to run Spring boot application with STS

I am starting to learn microservices with Spring Boot. I go to root of my project and run the command:

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:

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?

Edit 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!

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.

Also, please check Working directory in 'Run Configuration'. It should be something like "MODULE_DIR"

只需在main class右键单击并run as > spring boot/java application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM