application.yamlspring
spring: profiles: active: @profileActive@
application.propertiesbash
spring.profiles.active=@profileActive@
application-dev.yml、application-test.yml、application-prod.yml或者application-dev.properties、application-test.properties、application-prod.propertiesintellij-idea
<profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <profileActive>dev</profileActive> </properties> </profile> <profile> <id>test</id> <properties> <profileActive>test</profileActive> </properties> </profile> <profile> <id>prod</id> <properties> <profileActive>prod</profileActive> </properties> </profile> </profiles>
生產環境app
mvn clean package -Pprod -U # 或者 mvn clean package -DprofileActive=prod -U
測試環境maven
mvn clean package -Ptest -U # 或者 mvn clean package -DprofileActive=test -U
開發環境ide
mvn clean package -Pdev -U # 或者 mvn clean package -DprofileActive=dev -U