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

相关推荐
小江的记录本7 分钟前
【系统设计】《2026高频经典系统设计题》(秒杀系统、短链接系统、订单系统、支付系统、IM系统、RAG系统设计)(完整版)
java·后端·python·安全·设计模式·架构·系统架构
希望永不加班15 分钟前
SpringBoot 中 AOP 实现权限校验(角色/权限)
java·spring boot·后端·spring
桌面运维家26 分钟前
IDV云桌面vDisk机房部署方案模板特性解析
java·开发语言·devops
哈密瓜刨冰1 小时前
深入浅出 SpringMVC:核心注解全解析与实战用法
java
常利兵1 小时前
大文件上传不再卡顿:Spring Boot 分片上传、断点续传与进度条实现全解析
spring boot·后端·php
geNE GENT2 小时前
Spring Boot管理用户数据
java·spring boot·后端
怒放吧德德2 小时前
Spring Boot实战:Event事件机制解析与实战
java·spring boot·后端
wsx_iot2 小时前
arthas使用
java·arthas
㳺三才人子2 小时前
SpringDoc OpenAPI 配置問題
服务器·spring boot
lifallen3 小时前
Flink Watermark 设计分析
java·大数据·flink