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

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

Introduction

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

Prototype

@Override
    public void setActiveProfiles(String... profiles) 

Source Link

Usage

From source file:piecework.client.LoadTester.java

public static final void main(String[] args) throws Exception {
    String profile = args.length > 0 ? args[0] : "workstation";

    StandardEnvironment environment = new StandardEnvironment();
    environment.setActiveProfiles(profile);
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.setEnvironment(environment);//from   w  ww .j a  v a 2  s  . c om
    ctx.register(ClientConfiguration.class);
    ctx.refresh();

    KeyManagerCabinet cabinet = ctx.getBean(KeyManagerCabinet.class);
    SecuritySettings securitySettings = ctx.getBean(SecuritySettings.class);

    LoadTester loadTester = new LoadTester(cabinet.getKeystore(), securitySettings);
    loadTester.retrieveAllTasks();
}

From source file:org.springframework.boot.SpringApplication.java

private ConfigurableEnvironment convertToStandardEnvironment(ConfigurableEnvironment environment) {
    StandardEnvironment result = new StandardEnvironment();
    removeAllPropertySources(result.getPropertySources());
    result.setActiveProfiles(environment.getActiveProfiles());
    for (PropertySource<?> propertySource : environment.getPropertySources()) {
        if (!SERVLET_ENVIRONMENT_SOURCE_NAMES.contains(propertySource.getName())) {
            result.getPropertySources().addLast(propertySource);
        }/*  ww  w  .  jav a  2s. co m*/
    }
    return result;
}

From source file:org.springframework.xd.dirt.stream.FileSourceModuleTests.java

@Test
public void testSplitterUsesIterator() throws Exception {
    System.out.println(System.getProperty("user.dir"));
    ConfigurableApplicationContext ctx = new FileSystemXmlApplicationContext(
            new String[] { "../modules/common/file-source-common-context.xml",
                    "classpath:org/springframework/xd/dirt/stream/ppc-context.xml" },
            false);/*w  w w. j a  v  a2s. c  om*/
    StandardEnvironment env = new StandardEnvironment();
    Properties props = new Properties();
    props.setProperty("fixedDelay", "5");
    props.setProperty("timeUnit", "SECONDS");
    props.setProperty("initialDelay", "0");
    props.setProperty("withMarkers", "false");
    PropertiesPropertySource pps = new PropertiesPropertySource("props", props);
    env.getPropertySources().addLast(pps);
    env.setActiveProfiles("use-contents-with-split");
    ctx.setEnvironment(env);
    ctx.refresh();
    FileSplitter splitter = ctx.getBean(FileSplitter.class);
    File foo = File.createTempFile("foo", ".txt");
    final AtomicReference<Method> splitMessage = new AtomicReference<>();
    ReflectionUtils.doWithMethods(FileSplitter.class, new MethodCallback() {

        @Override
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            method.setAccessible(true);
            splitMessage.set(method);
        }
    }, new MethodFilter() {

        @Override
        public boolean matches(Method method) {
            return method.getName().equals("splitMessage");
        }
    });
    Object result = splitMessage.get().invoke(splitter, new GenericMessage<File>(foo));
    assertThat(result, instanceOf(Iterator.class));
    ctx.close();
    foo.delete();
}