Example usage for org.springframework.core.env ConfigurableEnvironment setActiveProfiles

List of usage examples for org.springframework.core.env ConfigurableEnvironment setActiveProfiles

Introduction

In this page you can find the example usage for org.springframework.core.env ConfigurableEnvironment setActiveProfiles.

Prototype

void setActiveProfiles(String... profiles);

Source Link

Document

Specify the set of profiles active for this Environment .

Usage

From source file:com.indeed.imhotep.web.config.PropertiesInitializer.java

private static void activateSpringProfiles(ConfigurableEnvironment springEnv) {
    if (IQLEnv.isSpringProfileSet(springEnv)) {
        return; // we seem to already have some profile set. let it be
    }//from   w  w w  .  j ava 2 s  .  c o  m

    // try to infer the appropriate Spring profile
    // this JVM system property should be set in OPs managed JVMs
    String indeedEnv = System.getProperty(indeedEnvironmentJVMProperty);
    if (Strings.isNullOrEmpty(indeedEnv)) {
        indeedEnv = "developer"; // assume this is not an OPs managed JVM and thus a developer station
    }
    final List<String> profiles = Lists.newArrayList(springEnv.getActiveProfiles());
    profiles.add(indeedEnv);
    springEnv.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
}

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

/**
 * Set the active profile to <strong>production</strong> for the web
 * application context./*from  ww w  .j  a v  a2s. c o  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./*w w  w . j  a v  a  2  s .c o m*/
 *
 * @param context the web application context.
 */
@Override
public void initialize(ConfigurableWebApplicationContext context) {
    ConfigurableEnvironment environment = context.getEnvironment();
    environment.setActiveProfiles("production");
}

From source file:org.carewebframework.api.spring.FrameworkAppContext.java

/**
 * Constructor for creating an application context. Disallows bean overrides by default.
 * //www . j a  v  a2s .co m
 * @param testConfig If true, use test profiles. If false, use production profiles.
 * @param locations Optional list of configuration file locations. If not specified, defaults to
 *            the default configuration locations ({@link #getDefaultConfigLocations}).
 */
public FrameworkAppContext(boolean testConfig, String... locations) {
    super();
    setAllowBeanDefinitionOverriding(false);
    setConfigLocations(locations == null || locations.length == 0 ? null : locations);
    ConfigurableEnvironment env = getEnvironment();
    env.setActiveProfiles(testConfig ? Constants.PROFILES_TEST : Constants.PROFILES_PROD);
    env.getPropertySources().addLast(new DomainPropertySource(this));
}

From source file:io.github.davejoyce.dao.composite.config.EnvironmentInitializer.java

public void initialize(ConfigurableApplicationContext context) {
    DeployedEnvironment deployEnv = DeployedEnvironment.detect(new CloudEnvironment().getInstanceInfo());
    ConfigurableEnvironment env = context.getEnvironment();
    System.setProperty("targetEnv", deployEnv.getEnvironmentName());
    env.setActiveProfiles(deployEnv.getEnvironmentName());
}

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 {//ww  w.ja  v  a2s  . c om
        log.info("Not running on Cloud Foundry, using 'default' profile");
        environment.setActiveProfiles("default");
    }
}

From source file:guru.qas.martini.jmeter.config.DefaultApplicationContextBuilder.java

protected void setProfiles(ConfigurableApplicationContext context) {
    String[] profileArray = getStringArray(profiles);
    if (null != profileArray && 0 < profileArray.length) {
        ConfigurableEnvironment environment = context.getEnvironment();
        environment.setActiveProfiles(profileArray);
    }/*from   w  w  w .  ja v a 2  s.c o  m*/
}

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:jp.xet.uncommons.web.env.EnvironmentProfileApplicationContextInitializer.java

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();

    String[] activeProfiles = environment.getActiveProfiles();
    if (ObjectUtils.isEmpty(activeProfiles)) {
        String propEnvironment = environment.getProperty("environment");
        if (Strings.isNullOrEmpty(propEnvironment)) {
            environment.setActiveProfiles("development");
            logger.warn("Spring active profiles are not specified.  Set default value [{}]", DEFAULT_PROFILE);
        } else {/*from ww w .ja  v  a  2  s .c  om*/
            environment.setActiveProfiles(propEnvironment);
            logger.info("Set Spring active profiles to [{}]", propEnvironment);
        }
    } else {
        logger.info("Spring active profiles [{}]", activeProfiles);
    }
}

From source file:com.pavikumbhar.javaheart.springconfiguration.ContextInitializer.java

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    System.out.println("com.pavikumbhar.javaheart.ContextInitializer.initialize()");
    try {/*  w  w w. j  a  v a 2  s  . co  m*/
        environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env.properties"));
        String profile = environment.getProperty("spring.profiles.active");
        environment.setActiveProfiles(profile);
        System.err.println(" spring.profiles.active profile :" + profile);
        System.err.println("env.properties loaded :" + ContextInitializer.class.getName());
    } catch (IOException e) {
        // it's ok if the file is not there. we will just log that info.
        System.out.println(
                "didn't find env.properties in classpath so not loading it in the AppContextInitialized");
    }
}