首页 > 解决方案 > Spring Boot 未加载活动的 application.properties 文件

问题描述

我正在使用 Spring Boot 根据此处记录的环境激活配置文件

在大多数情况下,它都有效。但是,我遇到了一个奇怪的情况。我有三个application-{profile}.properties文件如下:

application-dev.properties

application-uat.properties

application-release.properties

当我将战争文件部署到 uat 时,Spring 正在从发布文件中获取 JDBC 连接。application.properties 文件包含一行 -

spring.profiles.active=uat

如果我将 application-release.properties 文件的名称更改为 application-release.properties.tmp,那么 Spring 将从 application-uat.properties 中获取连接。有任何想法吗。顺便说一句,我正在使用 Spring.Boot 2.2.0-RELEASE

标签: spring-boot

解决方案


解决了!不确定我所做的两项更改中的哪一项解决了这个问题,但就是这样。

  1. 在阅读 Daniel Olszewski 文章中的评论时,Marcelo Martins 表示,当使用 'spring-boot-starter-parent' 时,无需在 pom.xml 中指定资源过滤,Daniel 进一步证实了这一点。当我使用“spring-boot-starter-parent”时,我将其删除。
    为了解决我的问题,我重新插入了它。
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        ...
    </build>
  1. 我将 maven 插件升级到 2.2.0.RELEASE
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.2.0.RELEASE</version>
    </plugin>

推荐阅读