解決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雖然已經在pom文件中寫了,有這個依賴,但是仍然不能啟動(不是報錯,是根本沒啟動).。
解決辦法:
我的情況是在pom依賴中添加了不必要的依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>2.2.3.RELEASE</version> </dependency>
這個autoconfigure看似方便了bean的配置,實際上有時候會導致一些問題,注釋掉該依賴,即可解決問題
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 { }
本質也是@MapperScan的注解掃包,只能對mybatis單獨使用,范圍較小
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Springboot之日志、配置文件、接口數(shù)據(jù)如何脫敏
本文主要介紹了Springboot之配置文件數(shù)據(jù)脫敏、接口返回數(shù)據(jù)脫敏、日志文件數(shù)據(jù)脫敏三個方面,需要了解學習的小伙伴快跟隨小編的腳步一起去看看吧2021-09-09Springboot中@RequestParam和@PathVariable的用法與區(qū)別詳解
這篇文章主要介紹了Springboot中@RequestParam和@PathVariable的用法與區(qū)別詳解,RESTful API設計的最佳實踐是使用路徑參數(shù)來標識一個或多個特定資源,而使用查詢參數(shù)來對這些資源進行排序/過濾,需要的朋友可以參考下2024-01-01一文詳解前端和后端的數(shù)據(jù)是如何連接的(基于Spring?Boot、Django或Node.js)
這篇文章主要介紹了前端和后端的數(shù)據(jù)是如何連接的相關資料,文中通過示例介紹的非常詳細,舉例講解的是基于Spring?Boot、Django或Node.js,需要的朋友可以參考下2025-01-01