maven如何利用springboot的配置文件进行多个环境的打包
在Spring Boot中多环境配置文件名需要满足application-{profiles.active}.properties的格式,其中{profiles.active}对应你的环境标识,可以随意命名,但js要与pom文件中环境标识一样。
至于哪个具体的配置文件会被加载,需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值。
需要在springboot的application.yml或者application.properties开发者_Go培训里面添加:
#标识环境
spring.profiles.active=@profiles.active@
在Spring Boot中多环境配置文件名需要满足application-{profiles.active}.properties的格式,其中{profiles.active}对应你的环境标识。
#开www.devze.com发环境spring.profiles.active=dev#测试环境spring.profiles.active=test#正式环境spring.profiles.active=prod
利用maven的profile,可以不用调整application文件就可以进行不同文件的打包:
1.修改pom.XML文件, 在resources里面加入
<resource><directory>src/main/resources</directory><filtering>true</filteriSBHJEgZOVng><includes><include>application.properties</include></includes></resource><resource><directory>src/main/resources/env</directory><filtering>true</filtering><includes><include>application-${profiles.active}.properties</include></includes></resource><resource><directory>src/main/resources</directory><includes><include>**/*.xml</include></includes><filtering>false</filtering></resource>
在build参数里面加入:
<plugins><p编程lugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><configuration>&lSBHJEgZOVt;delimiters><delimiter>@</delimiter></delimiters><useDefaultDelimiters>false</useDefaultDelimiters></configuration></plugin></plugins>
加入profiles参数:
<profiles><profile><id>dev</id><activation><!-- 默认环境 --><activeByDefault>true</activeByDefault></activation><properties><!-- 环境标识,需要与配置文件的名称相对应 --><profiles.active>dev</profiles.active></properties></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>
在idea中,勾选不同的profile环境配置,就可以打包不同环境的jar包或war包
指定环境类型打包使用,比如使用-P指定为dev
mvn compile package -DskipTests -Pdev
到此这篇关于maven如何利用springboot的配置文件进行多个环境的打包的文章就介绍到这了,更多相关springboot maven多个环境的打包内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
精彩评论