spring boot 不連接數據庫啟動


Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

用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項目啟動時,如果沒有配置數據庫配置,啟動時會拋出如下異常。

  1. Description:
  2.  
  3. Cannot determine embedded database driver class for database type NONE
  4.  
  5. Action:
  6.  
  7. If you want an embedded database please put a supported one on the classpath.
  8. If you have database settings to be loaded from a particular profile you may
  9. need to active it (no profiles are currently active).

2. 原因

springboot會自動注入數據源,而你卻沒有配,所以他就拋出該異常。

3. 如何不配

如果你只是簡單的想建個項目,並不需要數據庫支持,那么你可以讓他不去注入數據源。

    1. // 一般你啟動springboot項目,都會寫一個有@SpringBootApplication注解的類
    2. // 你在這個注解中添加exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}
    3. // 即可無數據庫運行
    4. // 如下
    5.  
    6. @ SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})


免責聲明!

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



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM