springboot+maven项目使用 profiles 配置多环境

227 阅读1分钟

pom.xml 添加 添加多环境配置

    <profiles>
        <profile>
            <id>local</id>
            <properties>
                <spring.active>local</spring.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>dev</id>
            <properties>
                <spring.active>dev</spring.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <spring.active>prod</spring.active>
            </properties>
        </profile>
    </profiles>

dev 和 pro 对应多环境配置文件

yml 配置

添加多环境配置

本地启动和打包都能自动对应配置文件

这样就可以直接使用maven 面板切换当前的环境的配置文件了 每次切换重新编译一下文件,防止缓存。

参考: