Package org.springframework.core.env

Examples of org.springframework.core.env.StandardEnvironment


  }

  @Test
  public void testWithActiveProfile() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
    provider.setEnvironment(env);
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
    assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(true));
  }
View Full Code Here


        .addPropertyValue("sex", "${key2}")
        .getBeanDefinition());

    System.setProperty("key1", "systemKey1Value");
    System.setProperty("key2", "systemKey2Value");
    ppc.setEnvironment(new StandardEnvironment());
    ppc.postProcessBeanFactory(bf);
    System.clearProperty("key1");
    System.clearProperty("key2");

    assertThat(bf.getBean(TestBean.class).getName(), is("systemKey1Value"));
View Full Code Here

  }

  private void assertSupportForComposedAnnotation(RootBeanDefinition beanDefinition) {
    beanFactory.registerBeanDefinition("config", beanDefinition);
    ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
    pp.setEnvironment(new StandardEnvironment());
    pp.postProcessBeanFactory(beanFactory);
    SimpleComponent simpleComponent = beanFactory.getBean(SimpleComponent.class);
    assertNotNull(simpleComponent);
  }
View Full Code Here

  }

  private void assertSupportForComposedAnnotationWithExclude(RootBeanDefinition beanDefinition) {
    beanFactory.registerBeanDefinition("config", beanDefinition);
    ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
    pp.setEnvironment(new StandardEnvironment());
    pp.postProcessBeanFactory(beanFactory);
    try {
      beanFactory.getBean(SimpleComponent.class);
      fail("Should have thrown NoSuchBeanDefinitionException");
    }
View Full Code Here

    }
  }

  @Test(expected=IllegalArgumentException.class)
  public void testStrictSystemPropertyReplacement() {
    PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false);
    System.setProperty("test.prop", "foo");
    try {
      editor.setAsText("${test.prop}-${bar}");
      Resource resolved = (Resource) editor.getValue();
      assertEquals("foo-${bar}", resolved.getFilename());
View Full Code Here

  }

  @Test(expected=IllegalArgumentException.class)
  public void testStrictSystemPropertyReplacement() {
    PropertyEditor editor = new ResourceArrayPropertyEditor(
        new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
        false);
    System.setProperty("test.prop", "foo");
    try {
      editor.setAsText("${test.prop}-${bar}");
      Resource[] resources = (Resource[]) editor.getValue();
View Full Code Here

    Map<String, Object> values = new HashMap<String, Object>();
    for (String name : nakedPS.getPropertyNames()) {
      values.put(fullyQualifiedKey(moduleDefinition, name), nakedPS.getProperty(name));
    }
    EnumerablePropertySource<?> modulePS = new MapPropertySource(propertySourceName, values);
    ConfigurableEnvironment moduleEnvironment = new StandardEnvironment();
    // Append the rootEnvironment
    moduleEnvironment.merge(rootEnvironment);
    // The global environment has been loaded by boot too and
    // its PS of interest was also named "applicationConfigurationProperties"
    moduleEnvironment.getPropertySources().addBefore(APPLICATION_CONFIGURATION_PROPERTIES, modulePS);
    return moduleEnvironment;
  }
View Full Code Here

  /**
   * Construct a new environment and use Spring Boot to populate its property sources using
   * {@link ConfigFileApplicationListener}.
   */
  private ConfigurableEnvironment loadPropertySources(final String searchLocation, final String baseName) {
    final ConfigurableEnvironment environment = new StandardEnvironment();
    environment.merge(parentEnvironment);
    new ConfigFileApplicationListener() {

      public void apply() {
        setSearchLocations(searchLocation);
        // We'd like to do 'setSearchNames(baseName)', but the environment property
        // has strong precedence and is already set for XD_CONFIG_NAME.
        Map<String, Object> singletonMap = Collections.singletonMap("spring.config.name",
            (Object) baseName);
        environment.getPropertySources().addFirst(
            new MapPropertySource("searchNamesOverride", singletonMap));
        addPropertySources(environment, resourceLoader);
      }
    }.apply();
    return environment;
View Full Code Here

      return this.environment;
    }
    if (this.webEnvironment) {
      return new StandardServletEnvironment();
    }
    return new StandardEnvironment();

  }
View Full Code Here

  @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

TOP

Related Classes of org.springframework.core.env.StandardEnvironment

Copyright © 2018 www.massapicom. 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.