解決springboot中mongodb不啟動及Dao不能被掃描到的問題
springboot中mongodb不啟動及Dao不能被掃描到
問題1
Field clipResultDao in nnu.ogms.demo.controller.GeoAnalysisController required a bean of type ‘Dao’ that could not be found
問題2
啟動spring boot,mongodb雖然已經(jīng)在pom文件中寫了,有這個依賴,但是仍然不能啟動(不是報錯,是根本沒啟動).。
解決辦法:
我的情況是在pom依賴中添加了不必要的依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>這個autoconfigure看似方便了bean的配置,實際上有時候會導(dǎo)致一些問題,注釋掉該依賴,即可解決問題
springboot掃dao層兩種方式和注意事項
錯誤:
***************************
APPLICATION FAILED TO START
***************************Description:
A component required a bean of type 'com.example.dao.AccountDao' that could not be found.
Action:Consider defining a bean of type 'com.example.dao.AccountDao' in your configuration.
Process finished with exit code 1
解決:
原因是啟動類沒有掃dao層的包
1,啟動類加注解
@MapperScan("dao層所在路徑")
并且路徑不能寫"com.example",com.example包下的controller和service層本來就會被自動掃描到,若想spring找到dao層要寫具體路徑"com.example.dao"或者"com.example.**.dao"
2,加配置類
@Configuration
@MapperScan({"com.qfedu.dao"})
public class MyBatisConfig {
}本質(zhì)也是@MapperScan的注解掃包,只能對mybatis單獨使用,范圍較小
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
JPA如何設(shè)置表名和實體名,表字段與實體字段的對應(yīng)
這篇文章主要介紹了JPA如何設(shè)置表名和實體名,表字段與實體字段的對應(yīng),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11
Struts2中validate數(shù)據(jù)校驗的兩種方法詳解附Struts2常用校驗器
這篇文章主要介紹了Struts2中validate數(shù)據(jù)校驗的兩種方法及Struts2常用校驗器,本文介紹的非常詳細(xì),具有參考借鑒價值,感興趣的朋友一起看看吧2016-09-09
MyBatis insert語句返回主鍵和selectKey標(biāo)簽方式
這篇文章主要介紹了MyBatis insert語句返回主鍵和selectKey標(biāo)簽方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09

