You can set the active profile in web.xml
file of your web application. Please see below code snippet:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev, testdb</param-value>
</context-param>
If their is no web.xml file and you are configuriong your web application using Java, then you can use WebApplicationInitializer
. Please see below code snippet:
class WebAppInitializer extends WebApplicationInitializer {
void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.getEnvironment().setActiveProfiles("profileName");
rootContext.register(SpringConfiguration.class);
container.addListener(new ContextLoaderListener(rootContext));
}
}
WebAppInitializer
need to be annotated with @Configuration
for this to work.
Please let me know if it helps or you need more help.