[关闭]
@Cesar 2016-02-26T10:09:34.000000Z 字数 2628 阅读 4692

Spring-boot 启动时碰到的Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package错误

Java

错误概述

最近学习springboot的使用,写了一个小demo,结果总是碰到这样的错误:

  1. ** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
  2. 2016-02-26 10:07:01.550 WARN 6112 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
  3. org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/cmc/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.2.5.RELEASE/spring-boot-autoconfigure-1.2.5.RELEASE.jar!/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$JdbcTemplateConfiguration.class]; nested exception is java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration due to internal class not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
  4. at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:303)
  5. at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:248)
  6. at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:140)
  7. at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:266)
  8. at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:230)
  9. at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:197)
  10. at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:166)
  11. at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:306)
  12. at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
  13. at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
  14. at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
  15. ...

解决方法

查了半天终于才stack overflow上看到了解决方案,链接如下:stack overflow
是因为application.java 文件不能直接放在main/java文件夹下,必须要建一个包把他放进去

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注