例子
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <project ...> ... <build> <resources> <directory>src/main/resources</directory> <excludes> <exclude>filters/*</exclude> ... </excludes> <filtering>true</filtering> <!-- 会用filter里的配置对resources文件里配置进行替换 --> </resources> <filters> <filter>${basedir}/src/main/resources/application-${env}.properties</filter> </filters> </build> <profiles> <profile> <id>dev</id> <properties> <env>dev</env> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> </profiles> </project>
|
application.properties
1
| jdbc.password=${jdbc.config.url}
|
filters/application-dev.properties
编译后target下application.properties里
其他环境同理,编译时指定profile即可。如mvn clean install -P prod即会使用filters/application-prod.properties下的配置进行替换。