Springboot项目 使用maven管理开发环境

文章介绍了如何在Springboot项目中利用maven配置管理开发、测试和生产环境。首先,创建相应的配置文件,然后在application.properties中设置动态激活的环境。接着,在pom.xml中定义不同环境的profile,如dev、test和prod,通过properties属性指定当前环境。最后,配置完成后系统会自动刷新,如果没有则手动刷新。

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

准备一个Springboot项目

过程很简单,不过多赘述,不太懂的小伙伴可以自行百度~~~

一、准备多环境配置文件

当前工程目录:
当前工程目录

二、application.properties配置

spring:
	profiles:
		active:	@profile.name@

三、pom.xml配置

<!-- 环境配置 -->
    <profiles>
        <!-- 开发 -->
        <profile>
            <id>dev</id>
            <activation>
                <!--默认激活配置-->
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!--当前环境-->
                <profile.name>dev</profile.name>
            </properties>
        </profile>
        <!-- 测试 -->
        <profile>
            <id>test</id>
            <properties>
                <!--当前环境-->
                <profile.name>test</profile.name>
            </properties>
        </profile>
        <!-- 生产 -->
        <profile>
            <id>prod</id>
            <properties>
                <!--当前环境,生产环境为空-->
                <profile.name>prod</profile.name>
            </properties>
        </profile>
    </profiles>

四、完成

正常情况下,配置完pom.xml后 此窗口会自动刷新,若没变化,可点击窗口左上角刷新按钮重试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值