springboot 沒(méi)法掃描到repository的解決
sprint boot2.0啟動(dòng)的時(shí)候報(bào)錯(cuò)!
A component required a bean of type 'XXX' that could not be found.
就是沒(méi)有掃描到我的repository包里的代碼
我先用@ComponentScan注解加上類所在的包名,沒(méi)有報(bào)錯(cuò),可以正常啟動(dòng)
但是坑爹的是@RestController注解下的Controller層的代碼沒(méi)有掃描到
就是說(shuō)http://127.0.0.1:8080可以正常訪問(wèn),但是Controller層配置的@RequestMapping都匹配不到
折騰了好久好久,比如@ComponentScan在加上Controller層的包名還是不行(導(dǎo)致repository包掃描不到),使用包名.*模糊匹配也不行,好坑爹,說(shuō)好的比spring mvc配置要簡(jiǎn)單的呢
最后我盯上了@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)注解
這個(gè)是因?yàn)樽铋_(kāi)始的時(shí)候項(xiàng)目啟動(dòng)報(bào)錯(cuò)沒(méi)有數(shù)據(jù)庫(kù)相關(guān)配置
然后我刪掉了注解里的exclude,開(kāi)始加上一些數(shù)據(jù)庫(kù)配置,比如
spring.datasource.url=jdbc:mysql://xxx.x.x.x/favorites?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver
這里的數(shù)據(jù)庫(kù)不是我本機(jī)的數(shù)據(jù)庫(kù),但是日志一直是報(bào)錯(cuò)連接的是連接我的本地?cái)?shù)據(jù)庫(kù)失敗
報(bào)錯(cuò)信息里查了一下DataSourceConfiguration這個(gè)類,猜測(cè)是配置的數(shù)據(jù)庫(kù)連接失敗之后開(kāi)始連接localhost的數(shù)據(jù)庫(kù)
然后加上了hikari的一些配置就能正常啟動(dòng),連接我配置的數(shù)據(jù)庫(kù),查詢sql都正常了
spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=15 spring.datasource.hikari.auto-commit=true spring.datasource.hikari.idle-timeout=30000 spring.datasource.hikari.pool-name=DatebookHikariCP spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1
定位過(guò)程真的是好心累!
補(bǔ)充:今天安裝spring的時(shí)候遇到一些缺少repository的問(wèn)題
在安裝spring的時(shí)候會(huì)對(duì)其依賴的一些庫(kù)的進(jìn)行一些鏈接檢查,導(dǎo)致會(huì)報(bào)一些缺少repository的問(wèn)題
No repository found containing: osgi.bundle,oracle.eclipse.tools.rest.lib,16.4.0.201705251324 No repository found containing: osgi.bundle,org.eclipse.cft.server.core,1.2.3.v201709130027 No repository found containing: osgi.bundle,org.eclipse.cft.server.rse,1.0.1.v201709130027 No repository found containing: osgi.bundle,org.eclipse.cft.server.standalone.core,1.0.4.v201709130027 No repository found containing: osgi.bundle,org.eclipse.cft.server.standalone.ui,1.0.4.v201709130027 No repository found containing: osgi.bundle,org.eclipse.cft.server.ui,1.0.110.v201709130027
stackvoerflow上找到了對(duì)應(yīng)的問(wèn)題和解決方案:地址
解決方法:
Go to Help → Install new software → Here uncheck “Contact all update sites during install to find required software”
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
- 淺談springboot @Repository與@Mapper的區(qū)別
- springboot使用redisRepository和redistemplate操作redis的過(guò)程解析
- springboot使用RedisRepository操作數(shù)據(jù)的實(shí)現(xiàn)
- springboot jpaRepository為何一定要對(duì)Entity序列化
- 解決springboot無(wú)法注入JpaRepository的問(wèn)題
- Springboot以Repository方式整合Redis的方法
- springboot不掃描@repository的問(wèn)題及解決
相關(guān)文章
Postgresql 查看SQL語(yǔ)句執(zhí)行效率的操作
這篇文章主要介紹了Postgresql 查看SQL語(yǔ)句執(zhí)行效率的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-02-02PostgreSQL教程(三):表的繼承和分區(qū)表詳解
這篇文章主要介紹了PostgreSQL教程(三):表的繼承和分區(qū)表詳解,本文講解了多表繼承、 繼承和權(quán)限、什么是分區(qū)表、分區(qū)表實(shí)現(xiàn)、分區(qū)和約束排除等內(nèi)容,需要的朋友可以參考下2015-05-05PostgreSQL 更新視圖腳本的注意事項(xiàng)說(shuō)明
這篇文章主要介紹了PostgreSQL 更新視圖腳本的注意事項(xiàng)說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01postgresql中wal_level的三個(gè)參數(shù)用法說(shuō)明
這篇文章主要介紹了postgresql中wal_level的三個(gè)參數(shù)用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12使用PostGIS完成兩點(diǎn)間的河流軌跡及流經(jīng)長(zhǎng)度的計(jì)算(推薦)
這篇文章主要介紹了使用PostGIS完成兩點(diǎn)間的河流軌跡及流經(jīng)長(zhǎng)度的計(jì)算,使用POSTGIS及其擴(kuò)展pgrouting計(jì)算給定兩點(diǎn)間的河流流經(jīng)區(qū)域和河流長(zhǎng)度,需要的朋友可以參考下2022-01-01