This is one of the most common problems when you starting your journey with SpringBoot. Fortunately its very easy to fix.
1. Problem
When you try to start your SpringBoot application you got the following error and the application doesn’t start:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.10.RELEASE) 2018-03-26 09:47:54.566 INFO 236 --- [ main] MyApp : Starting MyApp on *** with PID 236 (***\spring-value\build\classes\main started by *** in ***\spring-value) 2018-03-26 09:47:54.569 INFO 236 --- [ main] MyApp : No active profile set, falling back to default profiles: default 2018-03-26 09:47:54.644 INFO 236 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5123a213: startup date [Mon Mar 26 09:47:54 CEST 2018]; root of context hierarchy 2018-03-26 09:47:54.659 WARN 236 --- [ main] ionWarningsApplicationContextInitializer : ** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package. 2018-03-26 09:48:03.537 WARN 236 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/***/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/1.5.10.RELEASE/be96efab0d35181f18c486b0ec8d6a41a7042fce/spring-boot-autoconfigure-1.5.10.RELEASE.jar!/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$EmbeddedDatabaseConfiguration.class]; nested exception is java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$EmbeddedDatabaseConfiguration due to org/springframework/dao/DataAccessException not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake) 2018-03-26 09:48:03.541 INFO 236 --- [ main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2018-03-26 09:48:03.550 ERROR 236 --- [ main] o.s.boot.SpringApplication : Application startup failed ... org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-1.5.10.RELEASE.jar:1.5.10.RELEASE] ... 24 common frames omitted Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataAccessException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131] ... 26 common frames omitted Process finished with exit code 1
2. Cause
2.1. @SpringBootApplication annotation used on a class located in default package
This is the most common cause of the problem. You probably annotated your application class which is default package by @SpringBootApplication. The annotation consists of @ComponentScan annotation which is the real cause of the problem.
2.1.1. Solution
Move your class to different package i.e. “com.example.app“
2.2. Class located in default package is annotated by @ComponentScan annotation
This is the real cause of the problem. You cannot annotate class located in default package by @ComponentScan annotation.
2.2.1 Solution
Ensure that you really need to decorate your class by @ComponentScan annotation. If it is true try to move the class to named package like “com.example.app“.
At the end… May I ask you for something?
If I helped you solve your problem, please share this post. Thanks to this, I will have the opportunity to reach a wider group of readers. Thank You
Awesome, thanks for your solution.
Thanks 🙂
Thank you for such a great article it was really informative to me