這篇文章主要介紹了spring boot 不連接數據庫啟動的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教 |
spring boot 不連接數據庫啟動
用spring boot 搭建的項目,在配置文件不連接數據庫啟動項目會報錯。
原因在於
spring boot默認會加載
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
類,DataSourceAutoConfiguration類使用了@Configuration注解向spring注入了dataSource bean。因為工程中沒有關於dataSource相關的配置信息,當spring創建dataSource bean因缺少相關的信息就會報錯。
解決方法
在Application類上增加:
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
SpringBoot項目取消數據庫配置
1. 錯誤
springboot項目啟動時,如果沒有配置數據庫配置,啟動時會拋出如下異常。
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會自動注入數據源,而你卻沒有配,所以他就拋出該異常。
3. 如何不配
如果你只是簡單的想建個項目,並不需要數據庫支持,那么你可以讓他不去注入數據源。
一般你啟動springboot項目,都會寫一個有@SpringBootApplication注解的類
你在這個注解中添加
exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}
即可無數據庫運行
如下
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
以上為個人經驗,希望能給大家一個參考
本文地址:https://www.linuxprobe.com/spring-boot-application.html