Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Spring profile from system variable?

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.

like image 413
user2656851 Avatar asked Jul 22 '16 07:07

user2656851


People also ask

How to set active profile in environment in Spring Boot?

Once you have profile specific configuration, you would need to set the active profile in an environment. Use spring.profiles.active=prod in application.properties In this example let’s set it in application.properties. Lets add another property to application.properties

What are spring profiles?

Spring applications typically have a large set of such configurations that vary across environments. In such scenarios, you can use Spring profiles. Spring profiles provide a way to segregate parts of your application configuration and make it be available only in certain environments. In this post, we will learn how to use Spring profile. .

What is the use of defaultconfigurations in Spring Boot?

The DefaultConfigurations doesn’t have any Profile configured. Therefore, it will be available on all environments. However, the other configurations will be available only the specific active profiles. Spring Profiles are not limited to deployment environments. In other words, It can be used to bring any variation in application profile.

How to get the list of active profiles programmatically in spring?

Get Active Profiles Spring's active profiles drive the behavior of the @Profile annotation for enabling/disabling beans. However, we may also wish to access the list of active profiles programmatically. We have two ways to do it, using Environment or spring.active.profile. 6.1. Using Environment


1 Answers

SPRING_PROFILES_ACTIVE is the environment variable to override/pick Spring profile

like image 127
Lalit Jha Avatar answered Oct 23 '22 12:10

Lalit Jha