spring boot 不連接數(shù)據(jù)庫啟動的解決
spring boot 不連接數(shù)據(jù)庫啟動
用spring boot 搭建的項目,在配置文件不連接數(shù)據(jù)庫啟動項目會報錯。
原因在于
spring boot默認(rèn)會加載
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
類,DataSourceAutoConfiguration類使用了@Configuration注解向spring注入了dataSource bean。因為工程中沒有關(guān)于dataSource相關(guān)的配置信息,當(dāng)spring創(chuàng)建dataSource bean因缺少相關(guān)的信息就會報錯。
解決方法
在Application類上增加:
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
SpringBoot項目取消數(shù)據(jù)庫配置
1. 錯誤
springboot項目啟動時,如果沒有配置數(shù)據(jù)庫配置,啟動時會拋出如下異常。
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath.
If you have database settings to be loaded from a particular profile you may
need to active it (no profiles are currently active).
2. 原因
springboot會自動注入數(shù)據(jù)源,而你卻沒有配,所以他就拋出該異常。
3. 如何不配
如果你只是簡單的想建個項目,并不需要數(shù)據(jù)庫支持,那么你可以讓他不去注入數(shù)據(jù)源。
一般你啟動springboot項目,都會寫一個有@SpringBootApplication注解的類
你在這個注解中添加
exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}
即可無數(shù)據(jù)庫運(yùn)行
如下
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決使用@Component會導(dǎo)致spring.factories中的EnableAutoConfiguration無效
這篇文章主要介紹了解決使用@Component會導(dǎo)致spring.factories中的EnableAutoConfiguration無效問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-03-03
MyBatis中XML 映射文件中常見的標(biāo)簽說明
這篇文章主要介紹了MyBatis中XML 映射文件中常見的標(biāo)簽說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07
Mybatis實現(xiàn)自定義類型轉(zhuǎn)換器TypeHandler的方法
Mybatis實現(xiàn)自定義的轉(zhuǎn)換器非常的簡單,只需要三步就可以實現(xiàn)自定義類型轉(zhuǎn)換器TypeHandler,非常不錯,具有參考借鑒價值,感興趣的朋友一起看下吧2016-07-07

