在pom中引入profile
<profiles>
<profile>
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<!-- 默认环境 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
</properties>
</profile>
</profiles>
id:
properties: 可以配置一些属性
package.active自定义的名字
activeByDefault:默认激活的环境
激活方法
①:直接在application.yml的配置文件中使用 spring.profiles.active=dev|prod|test
spring.profiles.active=@profiles.active@
②:设置虚拟机参数 -Dspring.profiles.active=dev|prod|test
③:命令行参数启动(打成Jar包时候) java -jar xxx.jar – spring.profiles.active=dev|prod|test
④:通过maven命令参数 (即在使用maven打包时通过-P参数,-P后跟上profile的唯一id) mvn clean package -Pdev|prod|test
本文详细介绍了在Maven pom.xml中如何配置profile,包括dev、test和prod三种环境,并展示了如何激活这些profile。激活方式包括:在application.yml中设置spring.profiles.active,设置虚拟机参数,命令行参数启动以及通过maven命令参数-P指定profile。这些方法有助于在不同环境中灵活切换项目配置。
3653

被折叠的 条评论
为什么被折叠?



