温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springCloud集成nacos启动时报错怎么排查

发布时间:2023-04-12 15:41:59 来源:亿速云 阅读:110 作者:iii 栏目:开发技术

这篇文章主要介绍“springCloud集成nacos启动时报错怎么排查”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“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后面加上时区,这里我检查了一下我的mysql是8.0

    springCloud集成nacos启动时报错怎么排查

    排查二

    检查bootstrap.yml的配置是否和nacos中内容一致

    既然排除了我的数据库配置没问题,那么就需要检查一下我的项目是否能拉到nacos的配置

    对比如下,仔细检查后配置没有问题

    springCloud集成nacos启动时报错怎么排查

    排查三

    检查有无 spring-cloud-starter-bootstrap依赖

    在出问题的时候查阅了多方资料,都忽略了这个,因为检查了自己的pom包里面已经有了spring-cloud-starter的依赖,就没有考虑过加bootstrap的依赖,最后实在解决不了我的错,就报着试一下的心态去加了下面的依赖,好了!

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

    为什么要加bootstrap的依赖?

    我在项目中新加了一个bootstrap.yml,在这之前我只了解到bootstarp.yml的加载优先级比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>

    关于“springCloud集成nacos启动时报错怎么排查”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。

    向AI问一下细节

    免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

    AI