SpringBoot maven build war using specific application.properties

断了今生、忘了曾经 提交于 2021-02-08 05:09:00

问题


I have a Spring Boot application with has three application.properties files :

  1. application.properties
  2. application-qa.properties
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!