2 回答
TA贡献1805条经验 获得超9个赞
这几天一直被这个问题困扰,Spring boot启动没报错,就是扫描不到需要注册的类。今天终于发现,Spring boot的启动类需要放在需要扫描类的上层目录,这样才能扫描到同级或者子类需要注册的类。 但是在网上我发现一个其他问题,有人说用 @ComponentScan直接写需要扫描类的路径,但是我试验一直没成功。不知道为什么,麻烦帮忙看下! 刚接触spring boot 先谢谢各位了 。
下图是我要扫描的dao和service,但是启动后一直报错。报的错一看就是没扫描到类ReadingListRepository,这个类继承JpaRepository
2017-04-25 22:45:57.349 WARN 7864 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'readingListController': Unsatisfied dependency expressed through field 'readingListRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.dawn.oket.dao.ReadingListRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2017-04-25 22:45:57.349 INFO 7864 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-04-25 22:45:57.349 INFO 7864 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2017-04-25 22:45:57.349 INFO 7864 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2017-04-25 22:45:57.359 INFO 7864 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2017-04-25 22:45:57.399 INFO 7864 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-04-25 22:45:57.681 ERROR 7864 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field readingListRepository in org.dawn.oket.service.ReadingListController required a bean of type 'org.dawn.oket.dao.ReadingListRepository' that could not be found.
Action:
Consider defining a bean of type 'org.dawn.oket.dao.ReadingListRepository' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:52934', transport: 'socket'
Process finished with exit code 1
- 2 回答
- 0 关注
- 1022 浏览
添加回答
举报