Example usage for org.springframework.web.context.support AnnotationConfigWebApplicationContext getEnvironment

List of usage examples for org.springframework.web.context.support AnnotationConfigWebApplicationContext getEnvironment

Introduction

In this page you can find the example usage for org.springframework.web.context.support AnnotationConfigWebApplicationContext getEnvironment.

Prototype

@Override
public ConfigurableEnvironment getEnvironment() 

Source Link

Document

Return the Environment for this application context in configurable form, allowing for further customization.

Usage

From source file:com.biendltb.main_server.TripMapServer.java

private static WebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation(CONFIG_LOCATION);
    context.getEnvironment().setDefaultProfiles(DEFAULT_PROFILE);
    return context;
}

From source file:com.googlecode.jeeunit.example.spring.web.LibraryWebApplicationInitializer.java

@Override
public void onStartup(ServletContext sc) throws ServletException {

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.getEnvironment().addActiveProfile("web");
    rootContext.register(WebSpringConfig.class);
    sc.addListener(new ContextLoaderListener(rootContext));

    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.setParent(rootContext);
    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher",
            new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(2);/*from w w  w.jav a 2s. c  om*/
    dispatcher.addMapping("*.html");
    dispatcher.addMapping("*.form");
    dispatcher.addMapping("*.ajax");
}

From source file:org.shaigor.rest.retro.security.gateway.config.SecureWebAppInitializer.java

@Override
protected WebApplicationContext createServletApplicationContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.getEnvironment().setActiveProfiles("prod");
    context.scan(ClassUtils.getPackageName(getClass()));
    return context;
}

From source file:com.gantzgulch.sharing.configuration.WebInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.getEnvironment().setActiveProfiles("production");
    appContext.scan("com.gantzgulch.sharing");

    ContextLoaderListener contextListener = new ContextLoaderListener(appContext);
    servletContext.addListener(contextListener);

    DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("springSecurityFilterChain");
    FilterRegistration.Dynamic filter = servletContext.addFilter("securityFilter", filterProxy);
    filter.addMappingForUrlPatterns(null, false, "/*");

    AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
    webContext.register(MvcAppConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("sharing",
            new DispatcherServlet(webContext));
    dispatcher.setLoadOnStartup(1);/*w w w .j a  v a2s . c om*/
    dispatcher.addMapping("*.htm");
}

From source file:com.github.cherimojava.orchidae.Starter.java

private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    // set the Production profile to be active
    context.getEnvironment().setDefaultProfiles(RootConfig.PROFILE_PRODUCTION);
    context.register(RootConfig.class, WebMvcConfig.class);
    return context;
}

From source file:com.springsource.html5expense.web.ExpenseReportAppContextInitializer.java

@Override
public void initialize(AnnotationConfigWebApplicationContext applicationContext) {
    String profile = "local";
    if (isCloudFoundry()) {
        profile = "cloud";
    }/*  w ww.  j  a  va2  s .c o m*/
    applicationContext.getEnvironment().setActiveProfiles(profile);
    applicationContext.refresh();
}

From source file:org.shaigor.rest.retro.config.WebAppInitializer.java

/**
 * Creates web application context // w  ww.  ja va 2  s . co  m
 * @param servletContext to be used during creation and registration
 * @return web application context for the application
 */
private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.getEnvironment().setActiveProfiles("prod");
    Class<?>[] annotatedClasseses = configurations2Register();
    if (annotatedClasseses != null && annotatedClasseses.length > 0) {
        rootContext.register(annotatedClasseses);
    }
    rootContext.refresh();

    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.setInitParameter("defaultHtmlEscape", "true");

    return rootContext;
}

From source file:cz.muni.fi.editor.webapp.config.init.EditorApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    String bootLogo = "  __  __      _            _       _                   _ _ _             \n"
            + " |  \\/  |    | |          | |     | |                 | (_) |            \n"
            + " | \\  / | ___| |_ __ _  __| | __ _| |_ __ _    ___  __| |_| |_ ___  _ __ \n"
            + " | |\\/| |/ _ \\ __/ _` |/ _` |/ _` | __/ _` |  / _ \\/ _` | | __/ _ \\| '__|\n"
            + " | |  | |  __/ || (_| | (_| | (_| | || (_| | |  __/ (_| | | || (_) | |   \n"
            + " |_|  |_|\\___|\\__\\__,_|\\__,_|\\__,_|\\__\\__,_|  \\___|\\__,_|_|\\__\\___/|_|   \n"
            + "                                                                         \n"
            + "                                                                         ";

    System.out.println(ANSI_YELLOW + bootLogo + ANSI_RESET);

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.getEnvironment().setActiveProfiles("production");
    rootContext.register(WebAppConfiguration.class, SecurityConfig.class);

    servletContext.addListener(new ContextLoaderListener(rootContext));

    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(MvcConfiguration.class, WebSocketSecurityConfiguration.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(1);/*  www.  ja  v  a2 s  . c  om*/
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    servletContext.addFilter("encodingFilter", new CharacterEncodingFilter("UTF-8", true))
            .addMappingForUrlPatterns(null, false, "/*");

    servletContext.addFilter("httpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null,
            true, "/*");

}

From source file:io.gmind7.spring.foundation.config.WebAppInitializer.java

@Override
protected WebApplicationContext createRootApplicationContext() {
    Class<?>[] rootConfigClasses = this.getRootConfigClasses();
    if (!ObjectUtils.isEmpty(rootConfigClasses)) {
        AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
        String springProfilesActvie = rootAppContext.getEnvironment()
                .getProperty(EnvType.SPRING_PROFILE_ACTIVE.getKey());
        if (springProfilesActvie == null)
            rootAppContext.getEnvironment().setActiveProfiles(EnvType.DEFAULT_ACTIVE_PROFILE.getKey());
        rootAppContext.register(rootConfigClasses);
        return rootAppContext;
    } else {/*from   ww w .j  a  va 2 s .c o  m*/
        return null;
    }
}

From source file:org.uoiu.platform.web.DefaultWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    //    appContext.register(AppConfig.class);
    appContext.getEnvironment().setActiveProfiles("webapp");
    servletContext.addListener(new ContextLoaderListener(appContext));

    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(MvcConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(mvcContext));
    dispatcher.setLoadOnStartup(1);//ww w. j a va  2 s.  com
    dispatcher.addMapping("/");

    FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter",
            characterEncodingFilter());
    encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}