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中的配置

相关推荐
努力努力再努力wz5 分钟前
【c++深入系列】:万字详解模版(下)
java·c++·redis
还是大剑师兰特12 分钟前
Spring面试题及详细答案 125道(1-15) -- 核心概念与基础1
spring·大剑师·spring面试题·spring教程
瓦特what?1 小时前
关于C++的#include的超超超详细讲解
java·开发语言·数据结构·c++·算法·信息可视化·数据挖掘
是乐谷2 小时前
阿里云杭州 AI 产品法务岗位信息分享(2025 年 8 月)
java·人工智能·阿里云·面试·职场和发展·机器人·云计算
Java水解2 小时前
Java中的四种引用类型详解:强引用、软引用、弱引用和虚引用
java·后端
lifallen2 小时前
JCTools 无锁并发队列基础:ConcurrentCircularArrayQueue
java·开发语言·数据结构·算法
一叶飘零_sweeeet2 小时前
IDEA 插件 Trae AI 全攻略
java·人工智能·intellij-idea
欧哈东哥3 小时前
【C++】标准库中用于组合多个值的数据结构pair、tuple、array...
java·数据结构·c++
python_1363 小时前
web请求和响应
java·spring·github