700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > spring boot maven profiles 打包不同的配置文件

spring boot maven profiles 打包不同的配置文件

时间:2020-07-27 21:30:53

相关推荐

spring boot maven profiles 打包不同的配置文件

1. 在pom.xml添加

<profiles><profile><id>dev</id><properties><environment>dev</environment></properties></profile><profile><id>prod</id><properties><environment>prod</environment></properties></profile></profiles><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><executable>true</executable></configuration></plugin></plugins><resources><resource><filtering>true</filtering><directory>src/main/resources</directory>

<!--打包时,指不要这些文件--><excludes><exclude>application-dev.properties</exclude><exclude>application-prod.properties</exclude></excludes></resource><resource><filtering>true</filtering><directory>src/main/resources</directory><includes><include>application-${profileActive}.properties</include></includes></resource></resources></build>

2. 在 application.properties 增加 spring.profiles.active=@profileActive@

3. 使用 mvn clean package -P dev 打包,这样打包出的文件就不包含 application-prod.properties

注: 如果用 idea IDE , 运行的时候这里要选一下:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。