<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
配置文件名需要满足application-{profile}.properties
的格式。 {profile}对应的是环境标识,比如:
application-dev.properties :开发环境 application-test.properties:测试环境 application-prod.properties:生产环境
每个文件中可以配置不同的数据库地址,端口号等。
在application.properties中的配置动态配置文件,如下所示: spring.profiles.active: @spring.profiles.active@
<profiles>
<profile>
<id>dev</id>
<activation>
<!--默认激活-->
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<spring.profiles.active>test</spring.profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
</profiles>
mvn clean package -P dev
如果使用命令行直接运行jar文件,则使用java -jar -Dspring.profiles.active=test demo-0.0.1-SNAPSHOT.jar
发表时间:2020-08-24
本站文章除注明转载/出处外,皆为作者原创,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。