欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springCloud集成nacos啟動時報錯原因排查

 更新時間:2023年04月12日 14:41:26   作者:究極無敵懶人  
這篇文章主要介紹了springCloud集成nacos啟動時報錯原因排查,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

今早在集成nacos時啟動報如下錯:

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).


Process finished with exit code 1

排查一

檢查nacos中配置的database的配置

上面的錯誤描述明確的說了是datasource的url讀不到,那么第一反應是去檢查一下是不是配置錯誤了,nacos中配置的文件檢查了datasource的所有屬性沒有問題

??注意:這里可能會踩坑的是mysql的版本在8以下和8以上driver-class-name是不一樣的,8及以上需要在加上cj,還需要在url后面加上時區(qū),這里我檢查了一下我的mysql是8.0

排查二

檢查bootstrap.yml的配置是否和nacos中內容一致

既然排除了我的數據庫配置沒問題,那么就需要檢查一下我的項目是否能拉到nacos的配置

對比如下,仔細檢查后配置沒有問題

排查三

檢查有無 spring-cloud-starter-bootstrap依賴

在出問題的時候查閱了多方資料,都忽略了這個,因為檢查了自己的pom包里面已經有了spring-cloud-starter的依賴,就沒有考慮過加bootstrap的依賴,最后實在解決不了我的錯,就報著試一下的心態(tài)去加了下面的依賴,好了!

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

為什么要加bootstrap的依賴?

我在項目中新加了一個bootstrap.yml,在這之前我只了解到bootstarp.yml的加載優(yōu)先級比bootstrap.properties更高,但是springboot項目中如果沒有spring-cloud-context或者spring-cloud-starter-bootstrap的依賴的話是不會去讀取bootstrap.properties的,只會去讀application.properties,

  • spring boot 2.4版本以下加
<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring-cloud-context</artifactId> 
</dependency>
  • spring boot 2.4版本以上加
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論