Spring Boot java -jar --spring.profiles.active=dev 失效问题

之前动态部署修改配置文件的情况不多,所以也没注意过,这个问题今天困扰了好久,经过多方查询后得到了解决办法

直接上代码

xml 复制代码
<profiles>
        <profile>
            <!-- 本地开发环境 -->
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 生产环境 -->
            <id>prod</id>
            <properties>
                <profiles.active>prod</profiles.active>
            </properties>
        </profile>
        <profile>
            <!-- 测试环境 -->
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
        <profile>
            <!-- local环境 -->
            <id>local</id>
            <properties>
                <profiles.active>local</profiles.active>
            </properties>
        </profile>
    </profiles>


    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <!-- 资源根目录排除各环境的配置,防止在生成目录中多余其它目录 -->
                <excludes>
                    <exclude>test/*</exclude>
                    <exclude>prod/*</exclude>
                    <exclude>dev/*</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources/${profiles.active}</directory>
            </resource>
        </resources>
     </build>

yml中的配置

相关推荐
此木|西贝2 小时前
【设计模式】享元模式
java·设计模式·享元模式
李少兄3 小时前
解决Spring Boot多模块自动配置失效问题
java·spring boot·后端
bxlj_jcj4 小时前
JVM性能优化之年轻代参数设置
java·性能优化
八股文领域大手子4 小时前
深入理解缓存淘汰策略:LRU 与 LFU 算法详解及 Java 实现
java·数据库·算法·缓存·mybatis·哈希算法
不当菜虚困4 小时前
JAVA设计模式——(八)单例模式
java·单例模式·设计模式
m0_740154674 小时前
Maven概述
java·maven
他҈姓҈林҈4 小时前
Spring Boot 支持政策
spring boot
吗喽对你问好4 小时前
Java位运算符大全
java·开发语言·位运算
Java致死5 小时前
工厂设计模式
java·设计模式·简单工厂模式·工厂方法模式·抽象工厂模式