2 回答

TA貢獻(xiàn)1871條經(jīng)驗 獲得超8個贊
1.這幾天一直被這個問題困擾,Spring boot啟動沒報錯,就是掃描不到需要注冊的類。今天終于發(fā)現(xiàn),Spring boot的啟動類需要放在需要掃描類的上層目錄,這樣才能掃描到同級或者子類需要注冊的類。 但是在網(wǎng)上我發(fā)現(xiàn)一個其他問題,有人說用 @ComponentScan直接寫需要掃描類的路徑,但是我試驗一直沒成功。不知道為什么,麻煩幫忙看下! 剛接觸spring boot 先謝謝各位了 。
2.下圖是我要掃描的dao和service,但是啟動后一直報錯。報的錯一看就是沒掃描到類ReadingListRepository,這個類繼承JpaRepository
3.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 關(guān)注
- 917 瀏覽
添加回答
舉報