pom.xml文件
<profiles>
<profile>
<!-- dev -->
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<active>dev</active>
</properties>
</profile>
<profile>
<!-- prod -->
<id>prod</id>
<properties>
<active>prod</active>
</properties>
</profile>
</profiles>
yml文件配置
主配置文件定义的active
与xml的properties
对应的标签名一致
spring:
profiles:
active: @active@
测试
- application-dev.yml
server:
port: 8888
- application-prod.yml
server:
port: 8889
maven 打包传入active
打包命令:
mvn clean package -P prod
日志端口
2021-12-03 21:53:06.552 INFO 14964 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer :
Tomcat started on port(s): 8889 (http) with context path ''
dev环境同理,可自行测试…
常见问题
打包运行出现 xxx.jar中没有主清单属性
maven plugins中添加如下配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>