14
votes

I'm following a Spring tutorial, and when I tried to start the spring application I got the following error:

2016-01-20 23:18:15.907 INFO 5271 --- [ main] o.s.boot.SpringApplication : Starting SpringApplication v1.3.1.RELEASE on ...

2016-01-20 23:18:15.911 INFO 5271 --- [ main] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default

2016-01-20 23:18:15.918 ERROR 5271 --- [ main] o.s.boot.SpringApplication : Application startup failed java.lang.IllegalArgumentException: Sources must not be empty at org.springframework.util.Assert.notEmpty(Assert.java:276) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:352) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.main(SpringApplication.java:1140) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]

What is this "Sources must not be empty" error?

I am using an Eclipse - Maven project for this tutorial project and I have updated the project. I have also cleaned and rebuilt but I still got this error.

5
Have a look at the doRun method and see what the assertion is checkingMarged
Please add the relevant section of code, so people can offer more useful suggestions.betseyb
This can be caused by a dirty classpath with different versions of Spring libraries all over the place. Cleanup it and align it to the one and same Spring version with the correct versioned dependencies.Pratap A.K
Please add the related code, especially your SpringBootApplication or EnableAutoConfiguration annotated classAli Dehghani

5 Answers

24
votes

It turns out that I did not set the main class correctly in Eclipse - Debug, and Run configuration.

I set org.springframework.boot.SpringApplication as the main class.

The Main class should be pointing to my main class.

9
votes

you must add at least one main config class as a source (see attached screenshots).

wrong: enter image description here

right: enter image description here

8
votes

Run the main class & not the project.

5
votes

Had the same issue recently, turned out I was running the wrong java class. I went to class where I have my @SpringBootApplication and right click -> run as java application. Hopefully that will help someone.

1
votes

add scanBasePackages="com.login" at main class thats all your code will work.

package com.login.example.LoginExample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages="com.login")

public class LoginExampleApplication {

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