1. 程式人生 > 實用技巧 >SpringBoot框架:'url' attribute is not specified and no embedded datasource could be configured問題處理

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中配置資料庫的連線資訊,執行程式就不會報錯。