• 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>
  • 相关阅读:
    在线文本数字识别列表求和工具
    应用程序主题生成很简单!界面控件DevExtreme有现成的主题生成器
    HashMap底层源码,数据结构
    【Android笔记31】Android中数据存储之SQLite数据库(Cursor、execSQL、rawQuery)
    HTML开篇之安装VSvode(用记事本编辑HTML)
    USB模块分析(四)- 设备列表&权限申请
    MIPS寄存器堆
    【计算机网络】(谢希仁第八版)第三章课后习题答案
    定制化JDK升级引发的离奇事件
    【ES8】新特性
  • 原文地址:https://blog.csdn.net/dream_miracle/article/details/126369783