1

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!

Leandro Borges Ferreira
  • 12,422
  • 10
  • 53
  • 73
  • does it display main class name on console along with error? have a look at [this](http://stackoverflow.com/questions/28451120/spring-boot-program-cannot-find-main-class) – Sasi Kathimanda Feb 05 '17 at 19:20
  • No. This is the complete error message – Leandro Borges Ferreira Feb 05 '17 at 19:23
  • have you checked Run -> Run Configurations? ensure you don't have duplicated main classes – Sasi Kathimanda Feb 05 '17 at 19:25
  • In the Run Configurations the Main type is: br.com.leandroborgesferreira.microlearn.MicroLearnApplication . So it's correct – Leandro Borges Ferreira Feb 05 '17 at 19:50
  • can you post the class in the question. – Sasi Kathimanda Feb 05 '17 at 19:52
  • Could you also post the full exception log? Are you sure that the IDE, is properly configured to invoke your java app with the same jdk version you are invoking `mvn spring-boot:run` from your command line ? Also could you try simply invoking it as a java app instead of *Run as -> Spring Boot App* – AntJavaDev Feb 05 '17 at 20:00
  • @AntJavaDev 1- The error message is all the Console shows to me. 2- No... I am not sure, how can I do this? 3- If I try Run as -> Java Application or Run as -> Maven clean I get the same error – Leandro Borges Ferreira Feb 05 '17 at 20:07
  • give a look at this [tutorial](https://spring.io/blog/2015/03/18/spring-boot-support-in-spring-tool-suite-3-6-4). Regarding the jdk , at the run configuration window, there is a tab JRE , check there with which one you are invoking the app. – AntJavaDev Feb 05 '17 at 20:22
  • This is a Microservice I wrote, it is basically a starter and may be a good base for you to start with, however it is using gradle rather then maven. https://github.com/Rob-Leggett/gradle_springboot_microservice – Robert Leggett Feb 05 '17 at 20:51
  • what happens if you create a simple spring boot app using the "new spring starter project" wizard and run that? Does that work? – Martin Lippert Feb 06 '17 at 08:19

3 Answers3

1

just right click within main class and run as > spring boot/java application

pramod singh
  • 503
  • 2
  • 11
0

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"

Solorad
  • 904
  • 9
  • 21
0

Enter spring-boot:run in your configuration if using Spring Tools Suite 4 IDE

enter image description here