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.
applicationContext.xml
?applicationContext.xml
configuration?Articles on that subject or even examples would be most appreciated!! Thanks in advance.
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
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. .
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.
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
SPRING_PROFILES_ACTIVE is the environment variable to override/pick Spring profile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With