springboot maven 配置多环境部署

Posted 宣之于口

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot maven 配置多环境部署相关的知识,希望对你有一定的参考价值。

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

以上是关于springboot maven 配置多环境部署的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot多环境部署,在启动时动态设置相应的配置文件

jenkins多环境部署

jenkins多环境部署

5-5 Vue CLI多环境部署

5-5 Vue CLI多环境部署

如何高效完成ECS多环境部署?