Example usage for org.springframework.web.context ConfigurableWebApplicationContext getEnvironment

List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext getEnvironment

Introduction

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

Prototype

Environment getEnvironment();

Source Link

Document

Return the Environment associated with this component.

Usage

From source file:com.github.carlomicieli.config.ContextProfileInitializer.java

/**
 * Set the active profile to <strong>production</strong> for the web
 * application context.//from   w  w  w . j  a v  a2  s. co  m
 * @param context the web application context.
 */
@Override
public void initialize(ConfigurableWebApplicationContext context) {
    ConfigurableEnvironment environment = context.getEnvironment();
    environment.setActiveProfiles("dev");
}

From source file:com.github.carlomicieli.nerdmovies.config.ContextProfileInitializer.java

/**
 * Set the active profile to <strong>production</strong> for the web
 * application context.//from   w  w  w  .  j  a v  a2  s .  co m
 *
 * @param context the web application context.
 */
@Override
public void initialize(ConfigurableWebApplicationContext context) {
    ConfigurableEnvironment environment = context.getEnvironment();
    environment.setActiveProfiles("production");
}

From source file:com.goldengekko.meetr.ContextProfileInitializer.java

public void initialize(ConfigurableWebApplicationContext ctx) {
    ConfigurableEnvironment environment = ctx.getEnvironment();
    final String activeProfiles = ctx.getServletContext().getInitParameter("contxt.profile.initializer.active");
    final String[] profiles = activeProfiles.split(",");
    LOG.info("activating profiles {} from {}", profiles, activeProfiles);
    environment.setActiveProfiles(profiles);
}

From source file:com.rr.generic.ui.security.ContextProfileInitializer.java

public void initialize(ConfigurableWebApplicationContext ctx) {
    ConfigurableEnvironment environment = ctx.getEnvironment();

    String hostname = null;//from w  ww .ja  va  2 s .c o m
    String profiles = "local";

    try {
        hostname = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException ex) {
        Logger.getLogger(ContextProfileInitializer.class.getName()).log(Level.SEVERE, null, ex);
    }

    if ("172.24.16.43".equals(hostname)) {
        profiles = "staging";
    } else if ("172.24.32.41".equals(hostname)) {
        profiles = "prod";
    }

    environment.setActiveProfiles(profiles);
}

From source file:com.ut.healthelink.security.ContextProfileInitializer.java

public void initialize(ConfigurableWebApplicationContext ctx) {
    ConfigurableEnvironment environment = ctx.getEnvironment();

    String hostname = null;/*  ww w . j a va 2 s. co  m*/
    String profiles = "local";

    try {
        hostname = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException ex) {
        Logger.getLogger(ContextProfileInitializer.class.getName()).log(Level.SEVERE, null, ex);
    }

    if ("10.202.52.54".equals(hostname)) {
        profiles = "healthelink-test";
    } else if ("10.202.52.152".equals(hostname)) {
        profiles = "healthelink-prod";
    }

    environment.setActiveProfiles(profiles);
}

From source file:com.trenako.web.config.ContextProfileInitializer.java

@Override
public void initialize(ConfigurableWebApplicationContext context) {
    ConfigurableEnvironment environment = context.getEnvironment();

    if (cloudFoundryEnvironment.isOpenShift()) {
        environment.setActiveProfiles("cloud");
    } else {/*  w  ww.j  a  v a 2 s .  c om*/
        log.info("Not running on Cloud Foundry, using 'default' profile");
        environment.setActiveProfiles("default");
    }
}

From source file:edu.jhuapl.openessence.config.AppInitializer.java

private void addPropertySources(ConfigurableWebApplicationContext ctx) {
    ConfigurableEnvironment env = ctx.getEnvironment();

    // add properties that don't come from .properties files
    env.getPropertySources().addFirst(getBuiltinPropertySource(ctx));

    try {//  w  w w  .j  av  a2  s  .  c o  m
        Resource[] classpathPropResources = ctx.getResources("classpath:/config/*.properties");
        for (PropertySource<?> p : getPropertySources(Arrays.asList(classpathPropResources))) {
            env.getPropertySources().addFirst(p);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:de.dennishoersch.web.chat.spring.profiles.Profiles.java

private void setIfActive(ConfigurableWebApplicationContext applicationContext) {
    if (isActive(applicationContext)) {
        logger.debug(String.format("Profile '%s' is active.", this.name()));
        applicationContext.getEnvironment().addActiveProfile(this.name());
    }//from  w  ww. j a v a 2  s  . c o  m
}

From source file:alfio.config.Initializer.java

@Override
protected WebApplicationContext createRootApplicationContext() {
    ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext());
    Objects.requireNonNull(ctx, "Something really bad is happening...");
    ConfigurableEnvironment environment = ctx.getEnvironment();
    if (environment.acceptsProfiles(PROFILE_DEV)) {
        environment.addActiveProfile(PROFILE_HTTP);
    }/*w ww  .jav  a2s  . c o  m*/
    this.environment = environment;
    return ctx;
}

From source file:edu.jhuapl.openessence.config.AppInitializer.java

@Override
public void initialize(ConfigurableWebApplicationContext applicationContext) {
    addPropertySources(applicationContext);

    // see http://bugzilla.slf4j.org/show_bug.cgi?id=184 for why we need ""
    log.info("Active profiles: {}{}", "", applicationContext.getEnvironment().getActiveProfiles());
}