springboot maven 配置多环境部署

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/loy_184548/article/details/81940059

springboot maven 配置多环境部署

参考文章:here

1. 环境配置文件

spring boot允许你通过命名约定按照一定的格式 application-{profile}.properties来定义多个配置文件

将各环境配置文件放在/src/main/resources/目录下,例如:application-demo.properties

2. POM文件配置

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
        <!-- 配置默认 -->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>demo</id>
        <properties>
            <env>demo</env>
        </properties>
    </profile>
    <profile>
        <id>official</id>
        <properties>
            <env>official</env>
        </properties>
    </profile>
</profiles>

3. 激活配置

基本配置写在/src/main/resources/application.properties中:@env@ 在POM文件中配置

spring.profiles.active=@env@

4. 打包

mvn clean package -Pdev -U -Dmaven.test.skip=true  // 不同环境 -P${profileActive}

猜你喜欢

转载自blog.csdn.net/loy_184548/article/details/81940059