I currently set my Spring profile using the below two files (Web.xml & MyListener.java). I set the "MyProfile" variable value as JNDI in Admin console and everything works fine.
But i was wondering whether there is a way to achieve this through applicationcontext.xml. I can read the JNDI value from Admin console as shown below in the applicationcontext.xml but not sure whether Spring has any way to set the profile in the xml file.
Thanks in advance!
Web.xml
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>MyListener</param-value>
</context-param>
public class MyListener implements ApplicationContextInitializer<ConfigurableApplicationContext> {
public void initialize(ConfigurableApplicationContext applicationContext) {
String actProfile = applicationContext.getEnvironment().getProperty("MyProfile");
applicationContext.getEnvironment().setActiveProfiles(actProfile);
}
}
applicationcontext.xml
<jee:jndi-lookup id="MyProfile" jndi-name="MyProfile"/>