UrI not set 原因与处理方法

今天下午跑代码时发现,上午能跑的代码下午跑不了了。一直报 Url not set错误。

出现这个问题的主要原因,是因为代码中的@ConfigurationProperties(prefix="spring.datasource.druid")和application.properties配置文件中的前缀不一致的问题。

可是我的配置也没问题。


通过debug发现dataSource没有被注入任何yaml中的属性

怀疑yaml没被加载

打开target发现确实如此

在pom中添加响应配置,使打包yaml

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>


 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

清除target重启项目,运行成功。

 posted on 2022-08-26 15:15  夜深楼鼓  阅读(653)  评论(0编辑  收藏  举报