I would like to set the Profile using application.properties file with the entry:
mode=master
How to set spring.profiles.active in my context.xml file? init-param works only in a web.xml context.
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>"${mode}"</param-value>
</init-param>
There are a few ways to change active profiles, none of which take directly from a properties file.
<init-param>
as you are doing in your question. -Dspring.profiles.active="master"
ConfigurableEnvironment
from your ApplicationContext
and setActiveProfiles(String...)
programmatically with context.getEnvironment().setActiveProfiles("container");
You can use an ApplicationListener
to listen to context initialization. Explanations on how to do that here. You can use a ContextStartedEvent
ContextStartedEvent event = ...; // from method argument
ConfigurableEnvironment env = (ConfigurableEnvironment) event.getApplicationContext().getEnvironment();
env.setActiveProfiles("master");
You can get the value "master"
from a properties file as you see fit.
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