springboot maven 多环境配置

本文详细介绍如何在SpringBoot项目中进行多环境配置,包括使用yaml和properties文件,创建不同环境配置文件的方法,以及在pom.xml中配置profiles节点来区分开发、测试和生产环境。此外,还提供了使用maven命令打包对应环境程序的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载:springboot maven 多环境配置

1、Spring Boot项目下application.yaml(yaml支持中文)或者application.properties(properties不支持中文)

application.yaml

spring:
  profiles:
    active: @profileActive@

application.properties

spring.profiles.active=@profileActive@

2、spring boot 创建不同环境下的配置文件 ,命令规则:application-${?}.properties

3、pom.xml文件中配置profiles节点

<profiles>  
    <profile>  
        <id>dev</id>  
        <activation>  
            <activeByDefault>true</activeByDefault>  
        </activation>  
        <properties>  
            <profileActive>dev</profileActive>  
        </properties>  
    </profile>  
    <profile>  
        <id>test</id>  
        <properties>  
            <profileActive>test</profileActive>  
        </properties>  
    </profile>  
    <profile>  
        <id>prod</id>  
        <properties>  
            <profileActive>prod</profileActive>  
        </properties>  
    </profile>  
</profiles>  

4、使用maven命令打包成相应环境的程序包

生产环境

mvn clean package -Pprod -U  
# 或者
mvn clean package -DprofileActive=prod -U

测试环境

mvn clean package -Ptest -U  
# 或者
mvn clean package -DprofileActive=test -U

开发环境

mvn clean package -Pdev -U  
# 或者
mvn clean package -DprofileActive=dev -U

 

转载于:https://my.oschina.net/liuzidong/blog/2978543

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值