Springboot多环境开发

一、pom.xml文件配置

以下分别定义三个环境的属性

<!--使pom文件能在配置文件中用,使pom中的属性能在配置文件中被解析-->
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.2.0</version>
				<configuration>
					<useDefaultDelimiters>true</useDefaultDelimiters>
				</configuration>
			</plugin>
		</plugins>
<!--maven和spring boot的多环境开发,优先执行maven的-->
	<profiles>
		<!--开发环境-->
		<profile>
			<id>dev</id>
			<properties>
				<profile.active>dev</profile.active>
			</properties>
		</profile>
		<!--生产环境-->
		<profile>
			<id>pro</id>
			<properties>
				<profile.active>pro</profile.active>
			</properties>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
		</profile>
		<!--测试环境-->
		<profile>
			<id>test</id>
			<properties>
				<profile.active>test</profile.active>
			</properties>
		</profile>
	</profiles>

二、配置application.yml

# 设置启用哪个环境
spring:
  profiles:
    active: ${profile.active}
---
# 开发
spring:
  profiles: dev
server:
  port: 80

---
#生产
spring:
  profiles: pro
server:
  port: 81


---
# 测试
spring:
  profiles: test
server:
  port: 82

三、启动命令

1.指定环境启动
java -jar springboot.jar --spring.profiles.active=dev
2.指定端口启动
java -jar springboot.jar --server.port=88
两个参数可以一起使用
java -jar springboot.jar --spring.profiles.active=dev --server.port=88

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝朽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值