问题
I have a Spring Boot application with has three application.properties files :
- application.properties
- application-qa.properties
- application-prod.properties
I want build a war using maven by using one of the properties depending on the environment the application with be deployed too i.e dev, qa or prod.
How can I do this. I'm pretty new to Spring Boot.
回答1:
Setting the SPRING_PROFILES_ACTIVE environment variable will activate the intended profile. for example, in order to activate the qa profile, set the SPRING_PROFILES_ACTIVE environment variable to qa. Read more about profile specific properties here in Spring Boot Documentation.
回答2:
1. Aproach
On Linux environments
export SPRING_PROFILES_ACTIVE=qa
and you can check if it was set on OS with the command:
$ env
After that you can run:
./gradlew bootRun
So you'll be able to see this line on startup:
2018-05-17 17:33:21.722 INFO 8245 --- [main]
b.j.t.d.InteropDocumentosApplication : The following profiles are active: qa
2. Aproach
via gradle build:
on application.properties
spring.profiles.active=@activeProfile@
on build.gradle
import org.apache.tools.ant.filters.ReplaceTokens
processResources {
filter ReplaceTokens, tokens: [
activeProfile: project.property('activeProfile')
]
}
You can use a property called activeProfile. So you have to supply the qa value when you run the build:
./gradlew build -PactiveProfile=qa
来源:https://stackoverflow.com/questions/35757363/springboot-maven-build-war-using-specific-application-properties