Examples of ConfigurableEnvironment


Examples of org.springframework.core.env.ConfigurableEnvironment

  private static final Random random = new Random();

  @Test
  public void testLegitOptionResolution() {
    ConfigurableEnvironment parentEnv = new AbstractEnvironment() {

      @Override
      protected void customizePropertySources(MutablePropertySources propertySources) {
        propertySources.addFirst(singleton("user", "eric"));
      }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

  }

  @Test
  public void testIllegalOptionResolution() {
    ConfigurableEnvironment parentEnv = new AbstractEnvironment() {

      @Override
      protected void customizePropertySources(MutablePropertySources propertySources) {
        propertySources.addFirst(singleton("user", "eric"));
      }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

    /**
     * Sets the active profile.
     */
    @Override
    public void initialize(final ConfigurableApplicationContext applicationContext) {
        final ConfigurableEnvironment environment = applicationContext.getEnvironment();
        String envTarget = null;
        try {
            envTarget = getEnvTarget(environment);
            environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env-" + envTarget + ".properties"));

            final String activeProfiles = environment.getProperty("spring.profiles.active");
            logger.info("The active profiles are: {}", activeProfiles);

            environment.setActiveProfiles(activeProfiles.split(","));
        } catch (final IOException ioEx) {
            if (envTarget != null) {
                logger.warn("Didn't find env-{}.properties in classpath so not loading it in the AppContextInitialized", envTarget);
            }
        }

        final String persistenceTarget = environment.getProperty(PERSISTENCE_TARGET);
        if (persistenceTarget == null) {
            logger.info("Didn't find a value for variable: {}", PERSISTENCE_TARGET);
        } else {
            logger.trace("value for variable: {} is: {}", PERSISTENCE_TARGET, persistenceTarget);
        }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

  @Test
  public void customEnvironment() throws Exception {
    TestSpringApplication application = new TestSpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run();
    verify(application.getLoader()).setEnvironment(environment);
  }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

  @Test
  public void commandLinePropertySource() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run("--foo=bar");
    assertTrue(hasPropertySource(environment, CommandLinePropertySource.class,
        "commandLineArgs"));
  }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

  @Test
  public void commandLinePropertySourceEnhancesEnvironment() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addFirst(
        new MapPropertySource("commandLineArgs", Collections
            .<String, Object> singletonMap("foo", "original")));
    application.setEnvironment(environment);
    application.run("--foo=bar", "--bar=foo");
    assertTrue(hasPropertySource(environment, CompositePropertySource.class,
        "commandLineArgs"));
    assertEquals("foo", environment.getProperty("bar"));
    // New command line properties take precedence
    assertEquals("bar", environment.getProperty("foo"));
  }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

  @Test
  public void propertiesFileEnhancesEnvironment() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run();
    assertEquals("bucket", environment.getProperty("foo"));
  }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

      runListener.started();
    }

    try {
      // Create and configure the environment
      ConfigurableEnvironment environment = getOrCreateEnvironment();
      configureEnvironment(environment, args);
      for (SpringApplicationRunListener runListener : runListeners) {
        runListener.environmentPrepared(environment);
      }
      if (this.showBanner) {
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

  private int order = 0;

  @Override
  public void initialize(ConfigurableApplicationContext context) {
    ConfigurableEnvironment environment = context.getEnvironment();
    List<Class<?>> initializerClasses = getInitializerClasses(environment);
    if (initializerClasses.size() > 0) {
      applyInitializerClasses(context, initializerClasses);
    }
  }
View Full Code Here

Examples of org.springframework.core.env.ConfigurableEnvironment

    return this.order;
  }

  @Override
  public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    ConfigurableEnvironment environment = event.getEnvironment();
    if (!environment.containsProperty(VCAP_APPLICATION)
        && !environment.containsProperty(VCAP_SERVICES)) {
      return;
    }
    Properties properties = new Properties();
    addWithPrefix(properties, getPropertiesFromApplication(environment),
        "vcap.application.");
    addWithPrefix(properties, getPropertiesFromServices(environment),
        "vcap.services.");
    MutablePropertySources propertySources = environment.getPropertySources();
    if (propertySources
        .contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
      propertySources.addAfter(
          CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
          new PropertiesPropertySource("vcap", properties));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.