Package org.springframework.core.env

Examples of org.springframework.core.env.ConfigurableEnvironment


    assertThat(foo, instanceOf(String.class));
  }

  @Test
  public void getBean_withActiveProfile() {
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles("dev");

    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
    reader.setEnvironment(env);
    reader.loadBeanDefinitions(XML);
View Full Code Here


    servlet.destroy();
  }

  public void testEnvironmentOperations() {
    DispatcherServlet servlet = new DispatcherServlet();
    ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
    assertThat(defaultEnv, notNullValue());
    ConfigurableEnvironment env1 = new StandardServletEnvironment();
    servlet.setEnvironment(env1); // should succeed
    assertThat(servlet.getEnvironment(), sameInstance(env1));
    try {
      servlet.setEnvironment(new DummyEnvironment());
      fail("expected IllegalArgumentException for non-configurable Environment");
View Full Code Here

    AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
    child.setParent(parent);
    child.refresh();

    ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class);
    assertThat("unknown env", env, anyOf(
        sameInstance(parent.getEnvironment()),
        sameInstance(child.getEnvironment())));
    assertThat("expected child ctx env", env, sameInstance(child.getEnvironment()));
  }
View Full Code Here

  private static class TestContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
      ConfigurableEnvironment environment = applicationContext.getEnvironment();
      environment.getPropertySources().addFirst(new PropertySource<Object>("testPropertySource") {
        @Override
        public Object getProperty(String key) {
          return "name".equals(key) ? "testName" : null;
        }
      });
View Full Code Here

   * {@inheritDoc}
   * <p>Replace {@code Servlet}-related property sources.
   */
  @Override
  protected void initPropertySources() {
    ConfigurableEnvironment env = getEnvironment();
    if (env instanceof ConfigurableWebEnvironment) {
      ((ConfigurableWebEnvironment) env).initPropertySources(this.servletContext, null);
    }
  }
View Full Code Here

   * {@inheritDoc}
   * <p>Replace {@code Servlet}-related property sources.
   */
  @Override
  protected void initPropertySources() {
    ConfigurableEnvironment env = getEnvironment();
    if (env instanceof ConfigurableWebEnvironment) {
      ((ConfigurableWebEnvironment) env).initPropertySources(this.servletContext, this.servletConfig);
    }
  }
View Full Code Here

    pac.addApplicationListener(new SourceFilteringListener(pac, this));

    // The wac environment's #initPropertySources will be called in any case when the context
    // is refreshed; do it eagerly here to ensure portlet property sources are in place for
    // use in any post-processing or initialization that occurs below prior to #refresh
    ConfigurableEnvironment env = pac.getEnvironment();
    if (env instanceof StandardPortletEnvironment) {
      ((StandardPortletEnvironment) env).initPropertySources(pac.getServletContext(), getPortletContext(), getPortletConfig());
    }

    postProcessPortletApplicationContext(pac);
View Full Code Here

    wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

    // The wac environment's #initPropertySources will be called in any case when the context
    // is refreshed; do it eagerly here to ensure servlet property sources are in place for
    // use in any post-processing or initialization that occurs below prior to #refresh
    ConfigurableEnvironment env = wac.getEnvironment();
    if (env instanceof ConfigurableWebEnvironment) {
      ((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
    }

    postProcessWebApplicationContext(wac);
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

TOP

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

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.