亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

spring boot啟動不掃描創建bean怎么回事

spring boot啟動不掃描創建bean怎么回事

慕村9548890 2018-09-05 13:13:37
查看完整描述

2 回答

?
Cats萌萌

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

查看完整回答
反對 回復 2018-09-28
  • 2 回答
  • 0 關注
  • 1053 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號