Appearance

maven配合idea配置多环境配置文件

coderzhouyu2021-07-22 14:12工具 javaspring-boot切换配置文件

调整maven配置

在 pom.xml 中添加以下代码

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

调整spring-boot配置

在项目配置文件中添加以下代码

spring:
  profiles:
    # 选中默认配置
    active: '@spring.active@'

IDE中选择

然后在IDEA中选择环境即可

Last Updated 2023/10/4 23:12:45