溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)怎么排查

發(fā)布時(shí)間:2023-04-12 15:41:59 來(lái)源:億速云 閱讀:221 作者:iii 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要介紹“springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)怎么排查”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)怎么排查”文章能幫助大家解決問(wèn)題。

    今早在集成nacos時(shí)啟動(dòng)報(bào)如下錯(cuò):

    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的配置

    上面的錯(cuò)誤描述明確的說(shuō)了是datasource的url讀不到,那么第一反應(yīng)是去檢查一下是不是配置錯(cuò)誤了,nacos中配置的文件檢查了datasource的所有屬性沒(méi)有問(wèn)題

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

    springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)怎么排查

    排查二

    檢查bootstrap.yml的配置是否和nacos中內(nèi)容一致

    既然排除了我的數(shù)據(jù)庫(kù)配置沒(méi)問(wèn)題,那么就需要檢查一下我的項(xiàng)目是否能拉到nacos的配置

    對(duì)比如下,仔細(xì)檢查后配置沒(méi)有問(wèn)題

    springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)怎么排查

    排查三

    檢查有無(wú) spring-cloud-starter-bootstrap依賴

    在出問(wèn)題的時(shí)候查閱了多方資料,都忽略了這個(gè),因?yàn)闄z查了自己的pom包里面已經(jīng)有了spring-cloud-starter的依賴,就沒(méi)有考慮過(guò)加bootstrap的依賴,最后實(shí)在解決不了我的錯(cuò),就報(bào)著試一下的心態(tài)去加了下面的依賴,好了!

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

    為什么要加bootstrap的依賴?

    我在項(xiàng)目中新加了一個(gè)bootstrap.yml,在這之前我只了解到bootstarp.yml的加載優(yōu)先級(jí)比bootstrap.properties更高,但是springboot項(xiàng)目中如果沒(méi)有spring-cloud-context或者spring-cloud-starter-bootstrap的依賴的話是不會(huì)去讀取bootstrap.properties的,只會(huì)去讀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>

    關(guān)于“springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)怎么排查”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

    向AI問(wèn)一下細(xì)節(jié)

    免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

    AI