• 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

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

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

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

    排查三:检查有无 spring-cloud-starter-bootstrap依赖

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

    1. <dependency>
    2. <groupId>org.springframework.cloudgroupId>
    3. <artifactId>spring-cloud-starter-bootstrapartifactId>
    4. dependency>

    为什么要加bootstrap的依赖?

    我在项目中新加了一个bootstrap.yml,在这之前我只了解到bootstarp.yml的加载优先级比bootstrap.properties更高,但是springboot项目中如果没有spring-cloud-context或者spring-cloud-starter-bootstrap的依赖的话是不会去读取bootstrap.properties的,只会去读application.properties,

     spring boot 2.4版本以下加

    1. <dependency>
    2. <groupId>org.springframework.cloudgroupId>
    3. <artifactId>spring-cloud-contextartifactId>
    4. dependency>

    spring boot 2.4版本以上加

    1. <dependency>
    2. <groupId>org.springframework.cloudgroupId>
    3. <artifactId>spring-cloud-starter-bootstrapartifactId>
    4. dependency>
  • 相关阅读:
    数据治理----集中、分布的各种模式傻傻分不清楚
    【vue2第十三章】自定义指令 自定义v-loading指令
    python替换word文件中的图片
    Java项目:ssm+mysql医药进销存系统
    C语言实现四元数的乘法(三维矢量、四元数以及旋转矢量与四元数相乘源码)
    PC_OS IO方式之DMA传输方式
    大数据学习之Spark基础
    freeswitch的3XX重定向
    【ELM分类】基于matlab遗传算法优化ELM神经网络数据分类【含Matlab源码 2138期】
    分布式唯一ID
  • 原文地址:https://blog.csdn.net/dream_miracle/article/details/126369783