spring boot啟動報錯Error starting ApplicationContext(未能配置數據源)


 

 

主要錯誤:

 

 

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

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

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-03 09:47:45.300 ERROR 23160 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
 
***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
 
Reason: Failed to determine a suitable driver class
 
 
Action:
 
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).

由第一幅圖知,最先發生錯誤的地方在創建datasource這個Bean,之后造成dao,service,controller都報錯了

我使用application.properties配置文件時出現此錯誤(換成application.yml時沒有出現此錯誤)

原因:

com.mysql.jdbc.Driver的版本太低,與springboot不兼容(springboot使用的2.3.2.RELEASE)
  <!-- mysql驅動 -->
       <!-- 此版本太低--> 
       <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
        </dependency>

 

更換以下依賴后正常了

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.21</version>
        </dependency>

總結:使用application.properties配置文件時springboot的2.3.2.RELEASE與mysql-connector-java的5.1.18不兼容

 

其他可能的原因,又看到這篇寫的比較多,評論也多

查看:

https://blog.csdn.net/qq_40223688/article/details/88191732


免責聲明!

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



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