springboot结合manven动态切换多环境配置文件

一、 首先在pom中加入如下配置

	<profiles>
	        <profile>
	            <!--不同环境Profile的唯一id-->
	            <id>dev</id>
	            <properties>
	                <profiles.active>dev</profiles.active>
	            </properties>
	        </profile>
	        <profile>
	            <id>prod</id>
	            <properties>
	                <profiles.active>prod</profiles.active>
	            </properties>
	            <activation>
	                <activeByDefault>true</activeByDefault>
	            </activation>
	        </profile>
	         <profile>
	            <id>pro</id>
	            <properties>
	                <profiles.active>pro</profiles.active>
	            </properties>
	            <activation>
	                <activeByDefault>true</activeByDefault>
	            </activation>
	        </profile>
	        <profile>
	            <id>test</id>
	            <properties>
	                <profiles.active>test</profiles.active>
	            </properties>
	        </profile>
	 </profiles>  
 
     <build>
 		<plugins>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <delimiters>@</delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

二、pom文件中添加好配置之后刷新maven之后就会出现如下按钮

勾选按钮实现动态切换配置文件

三、最后在application.yml中配置如下参数即可配置主配置文件

如此便实现了勾选按钮动态切换多环境配置文件,需要注意的是每次勾选按钮之后要刷新,最好是clean一下,很多时候会有缓存

spring:
  profiles:
    active: @profiles.active@
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值