Package org.springframework.core.env

Examples of org.springframework.core.env.StandardEnvironment


    // Inherit Environment if possible
    if (this.registry instanceof EnvironmentCapable) {
      this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
    }
    else {
      this.environment = new StandardEnvironment();
    }
  }
View Full Code Here


  private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry) {
    Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
    if (registry instanceof EnvironmentCapable) {
      return ((EnvironmentCapable) registry).getEnvironment();
    }
    return new StandardEnvironment();
  }
View Full Code Here

   * Create and return a new {@link StandardEnvironment}.
   * <p>Subclasses may override this method in order to supply
   * a custom {@link ConfigurableEnvironment} implementation.
   */
  protected ConfigurableEnvironment createEnvironment() {
    return new StandardEnvironment();
  }
View Full Code Here

   * {@link Service @Service}, and {@link Controller @Controller}
   * stereotype annotations
   * @see #registerDefaultFilters()
   */
  public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) {
    this(useDefaultFilters, new StandardEnvironment());
  }
View Full Code Here

  @Test
  public void testDefaultProfile() {
    {
      DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
      ConfigurableEnvironment env = new StandardEnvironment();
      env.setDefaultProfiles("custom-default");
      reader.setEnvironment(env);
      reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_ELIGIBLE_XML, getClass()));

      assertThat(beanFactory, not(containsTargetBean()));
    }
    {
      DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
      ConfigurableEnvironment env = new StandardEnvironment();
      env.setDefaultProfiles("custom-default");
      reader.setEnvironment(env);
      reader.loadBeanDefinitions(new ClassPathResource(CUSTOM_DEFAULT_ELIGIBLE_XML, getClass()));

      assertThat(beanFactory, containsTargetBean());
    }
View Full Code Here

    assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, "other"), not(containsTargetBean()));

    {
      DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
      ConfigurableEnvironment env = new StandardEnvironment();
      env.setActiveProfiles(DEV_ACTIVE);
      env.setDefaultProfiles("default");
      reader.setEnvironment(env);
      reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
      assertThat(beanFactory, containsTargetBean());
    }
    {
      DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
      ConfigurableEnvironment env = new StandardEnvironment();
      // env.setActiveProfiles(DEV_ACTIVE);
      env.setDefaultProfiles("default");
      reader.setEnvironment(env);
      reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
      assertThat(beanFactory, containsTargetBean());
    }
    {
      DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
      ConfigurableEnvironment env = new StandardEnvironment();
      // env.setActiveProfiles(DEV_ACTIVE);
      //env.setDefaultProfiles("default");
      reader.setEnvironment(env);
      reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
      assertThat(beanFactory, containsTargetBean());
View Full Code Here

  private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry) {
    Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
    if (registry instanceof EnvironmentCapable) {
      return ((EnvironmentCapable) registry).getEnvironment();
    }
    return new StandardEnvironment();
  }
View Full Code Here


  private BeanDefinitionRegistry beanFactoryFor(String xmlName, String... activeProfiles) {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    StandardEnvironment env = new StandardEnvironment();
    env.setActiveProfiles(activeProfiles);
    reader.setEnvironment(env);
    reader.loadBeanDefinitions(new ClassPathResource(xmlName, getClass()));
    return beanFactory;
  }
View Full Code Here

  @Override
  protected ConfigurationClassParser newParser() {
    return new ConfigurationClassParser(
        new CachingMetadataReaderFactory(),
        new FailFastProblemReporter(),
        new StandardEnvironment(),
        new DefaultResourceLoader(),
        new AnnotationBeanNameGenerator(),
        new DefaultListableBeanFactory());
  }
View Full Code Here

  }

  @Test
  public void testWithInactiveProfile() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles("other");
    provider.setEnvironment(env);
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
    assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false));
  }
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.