In my application I have beans annotated with @Profile(\"prod\") and @Profile(\"demo\").
The first one, as you can guess :), is used on beans that
I have the same issue, but I use WebApplicationInitializer in order to configure the ServletContext programmatically (Servlet 3.0+). So I do the following:
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext sc) throws ServletException {
// Create the 'root' Spring application context
final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
// Default active profiles can be overridden by the environment variable 'SPRING_PROFILES_ACTIVE'
rootContext.getEnvironment().setDefaultProfiles("prod");
rootContext.register(AppConfig.class);
// Manage the lifecycle of the root application context
sc.addListener(new ContextLoaderListener(rootContext));
}
}