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

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

Introduction

In this page you can find the example usage for org.springframework.web.context.support XmlWebApplicationContext 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.quartzdesk.executor.web.spring.SpringProfilesActivator.java

@Override
public void initialize(XmlWebApplicationContext applicationContext) {
    ConfigurableEnvironment env = applicationContext.getEnvironment();

    WorkDir workDir;/*  w  ww .  j av  a2s.c  o  m*/
    try {
        workDir = new WorkDir(applicationContext.getServletContext());
    } catch (IOException e) {
        throw new ApplicationContextException("Error obtaining QuartzDesk Executor work directory.", e);
    }

    String databaseProfile = getDatabaseProfile(workDir);

    String[] activeProfiles = new String[] { databaseProfile };

    log.info("Activating Spring profiles: {}", Arrays.toString(activeProfiles));

    env.setActiveProfiles(activeProfiles);
}

From source file:org.alfresco.bm.web.WebApp.java

@Override
public void onStartup(ServletContext container) {
    // Grab the server capabilities, otherwise just use the java version
    String javaVersion = System.getProperty("java.version");
    String systemCapabilities = System.getProperty(PROP_SYSTEM_CAPABILITIES, javaVersion);

    String appDir = new File(".").getAbsolutePath();
    String appContext = container.getContextPath();
    String appName = container.getContextPath().replace(SEPARATOR, "");

    // Create an application context (don't start, yet)
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocations(new String[] { "classpath:config/spring/app-context.xml" });

    // Pass our properties to the new context
    Properties ctxProperties = new Properties();
    {/*from   w w w.  j  ava 2s.c  o m*/
        ctxProperties.put(PROP_SYSTEM_CAPABILITIES, systemCapabilities);
        ctxProperties.put(PROP_APP_CONTEXT_PATH, appContext);
        ctxProperties.put(PROP_APP_DIR, appDir);
    }
    ConfigurableEnvironment ctxEnv = ctx.getEnvironment();
    ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource(appName, ctxProperties));
    // Override all properties with system properties
    ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource("system", System.getProperties()));
    // Bind to shutdown
    ctx.registerShutdownHook();

    ContextLoaderListener ctxLoaderListener = new ContextLoaderListener(ctx);
    container.addListener(ctxLoaderListener);

    ServletRegistration.Dynamic jerseyServlet = container.addServlet("jersey-serlvet", SpringServlet.class);
    jerseyServlet.setInitParameter("com.sun.jersey.config.property.packages", "org.alfresco.bm.rest");
    jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    jerseyServlet.addMapping("/api/*");
}

From source file:org.springframework.xd.dirt.server.AdminServer.java

public AdminServer(AdminOptions adminOptions) {
    XmlWebApplicationContext parent = new XmlWebApplicationContext();
    parent.getEnvironment().setActiveProfiles(ADMIN_PROFILE);
    parent.setConfigLocation("classpath:" + XDContainer.XD_INTERNAL_CONFIG_ROOT + "xd-global-beans.xml");

    this.webApplicationContext = new XmlWebApplicationContext();
    this.webApplicationContext
            .setConfigLocation("classpath:" + XDContainer.XD_INTERNAL_CONFIG_ROOT + "admin-server.xml");
    this.webApplicationContext.setParent(parent);

    OptionUtils.configureRuntime(adminOptions, parent.getEnvironment());
    OptionUtils.configureRuntime(adminOptions, this.webApplicationContext.getEnvironment());
    parent.refresh();/*from ww  w. j a v  a2  s . co m*/

    this.port = Integer
            .valueOf(this.webApplicationContext.getEnvironment().getProperty(XDPropertyKeys.XD_HTTP_PORT));

    webApplicationContext.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {

        @Override
        public void onApplicationEvent(ContextClosedEvent event) {
            stop();
        }
    });
    webApplicationContext.registerShutdownHook();
}