Default profile in Spring 3.1

前端 未结 7 1104
执笔经年
执笔经年 2020-11-28 19:56

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

7条回答
  •  难免孤独
    2020-11-28 20:40

    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));
        }
    }
    

提交回复
热议问题