nacos-group / nacos-spring-boot-project

Nacos ECO Project for Spring Boot
Apache License 2.0
789 stars 424 forks source link

获取不到nacos配置中心的spring.datasource相关参数 #266

Closed pjslina closed 2 years ago

pjslina commented 2 years ago

springboot+mybatisplus+druid+nacos-config,项目启动的时候DruidDataSourceAutoConfigure创建DruidDataSourceWrapper失败,因为DataSourceProperties的属性没有从配置中心获取到值。

错误日志: 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).

说明: 如果我将nacos-config-spring-boot-starter换成spring-cloud-starter-alibaba-nacos-config依赖,项目是正常的。

pjslina commented 2 years ago

springboot版本 2.6.3

com.alibaba.boot nacos-config-spring-boot-starter 0.2.12
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.5.2</version>
        <exclusions>
            <exclusion>
                <artifactId>HikariCP</artifactId>
                <groupId>com.zaxxer</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.2.8</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.29</version>
        <scope>runtime</scope>
    </dependency>
pjslina commented 2 years ago

验证了没有问题,我的配置文件是yaml格式,nacos和springboot集成,如果dataId没有指定后缀名称yaml的话,默认是使用properties格式的配置文件。