springBoot通过maven插件打包多环境配置文件

项目场景:

1.springBoot搭建多环境配置文件目录

我打的是jar包
在这里插入图片描述

2.修改项目pom.xml文件

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

在这里插入图片描述

找到build标签下的plugins标签,加载resource插件

<!-- resource插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>test-resources</id>
						<!--目标执行的阶段,具体值看Maven的生命周期列表;-->
						<phase>compile</phase>
						<!--一个plugin的execution的目标列表,也就是上面的id-->
						<goals>
							<goal>testResources</goal>
						</goals>
						<configuration>
							<!-- 覆盖原有文件 -->
							<overwrite>true</overwrite>
							<outputDirectory>${project.build.outputDirectory}</outputDirectory>
							<!-- 待处理的资源定义 -->
							<resources>
								<resource>
									<!-- 指定resources插件处理哪个目录下的资源文件 -->
									<!--suppress UnresolvedMavenProperty -->
									<directory>src/main/conf/${environment}</directory>
									<filtering>false</filtering>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>

验证结果:

无profile选择情况下,会把src/main/resource/application.yml打进去

在这里插入图片描述

提示:profile选择dev

在这里插入图片描述
在这里插入图片描述

提示:profile选择prod

在这里插入图片描述
在这里插入图片描述
参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值