How to set Spring profile from system variable?

user2656851 picture user2656851 · Jul 22, 2016 · Viewed 171.6k times · Source

I have a Spring project which uses another project. Each project has its own spring profile initialize from java code using applicationContext.xml and *.properties for each profile. I inject the profile from args[]. The problem is that second project uses the default configuration for the env from the applicationContext.xml I can not inject the env from args[] to the second project and I tried looking for an article which will explain how Spring profile works.

  1. Is there a hierarchy on which it will look the profile when default is not configured at applicationContext.xml ?
  2. Is System var stronger than applicationContext.xml configuration?
  3. What you think is the best solution to my challenge?

Articles on that subject or even examples would be most appreciated!! Thanks in advance.

Answer

Lalit Jha picture Lalit Jha · Sep 5, 2017

SPRING_PROFILES_ACTIVE is the environment variable to override/pick Spring profile