在实际部署过程中,我们有本地开发环境,测试环境,生产环境。
maven prefile 特性为我们提供了对,不同环境配置文件的管理,
通过对prefile的设置,在编译时 自动加载 相应环境的配置文件。
设置如下:
在 pom.xml 中加入如下配置:
<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>product</id>
<properties>
<profiles.active>product</profiles.active><!--生产环境 -->
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springfra

本文介绍了如何使用Maven的prefile特性管理SpringBoot应用在不同环境(开发、测试、生产)的配置文件。通过在pom.xml中配置,结合application.properties和特定环境的properties文件,实现编译时自动加载对应环境的配置。设置完成后,需要清理工程并重新编译,以确保加载正确环境的配置。


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



