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>
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
RxJava+Retrofit+Mvp實現(xiàn)購物車
這篇文章主要為大家詳細介紹了RxJava+Retrofit+Mvp實現(xiàn)購物車功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05SpringBoot注解篇之@Resource與@Autowired的使用區(qū)別
@Resource 注解和 @Autowired 注解都是在 Spring Framework 中進行依賴注入的注解,那么你知道他們有什么區(qū)別嗎,本文就來介紹一下2023-12-12詳解hashCode()和equals()的本質區(qū)別和聯(lián)系
這篇文章主要介紹了詳解hashCode()和equals()的本質區(qū)別和聯(lián)系,本文先對兩種方法作了介紹,然后對二者聯(lián)系進行分析,具有一定參考價值,需要的朋友可以了解下。2017-09-09