SpringBoot框架:'url' attribute is not specified and no embedded datasource could be configured問題處理


一、問題如下:

  Description:    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

         未能配置數據源:“url”屬性未指定,無法配置嵌入式數據源。

  Reason:         Failed to determine a suitable driver class.

         無法確定合適的驅動程序類別。

  

二、 問題解決:

  1、問題分析:

  在程序的配置文件中添加引入了數據庫驅動依賴包,springboot程序就自動去進行數據連接,但是因為沒有配置數據庫的連接信息,所以就會報錯。

  2、問題解決:

  (1)去掉自動連接:

  在未配置數據庫連接信息時,可以將入口類中的注解修改為以下代碼:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

  即添加(exclude = {DataSourceAutoConfiguration.class}),排除自動連接。

  (2)配置數據源信息:

  在application.yml中配置數據庫的連接信息,運行程序就不會報錯。

 


免責聲明!

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



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