idea 啟動springboot項目時報錯:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource


idea 啟動springboot項目時報錯:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource

 

 

 

原因:

項目配置在maven依賴中有mysql,且在配置文件中配置了DataSource

Spring Boot會自動根據jar包的依賴來自動配置項目,例如當你項目下面有HSQLDB的依賴,Spring Boot會自動創建默認的內存數據庫的數據源DataSource,但我們使用Mybatis自定義配置,想自己創建DataSource時就必須注釋掉DataSourceAutoConfiguration。

 

解決辦法:

1.

因此我們需要在Application類上面增加注解,排除自動按照依賴加載DataSource

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

 

 

 

2.@SpringCloudApplication

通過配置文件來設置

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource 【報錯】org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketHandlerMapping' defined in class path resource 新建項目用flyway數據遷移時報錯找不到flyway org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource Spring AOP 報錯org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXXXX' defined in class path resource.......... 使用security報錯:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' defined in class path resource Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM