Package org.springframework.context

Examples of org.springframework.context.ConfigurableApplicationContext.refresh()


    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo");
      ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue"));
      ctx.refresh(); // should succeed
    }
  }


  private DefaultListableBeanFactory newBeanFactoryWithEnvironmentAwareBean() {
View Full Code Here


  }

  @Test
  public void genericApplicationContext_standardEnv() {
    ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
    ctx.refresh();

    assertHasStandardEnvironment(ctx);
    assertEnvironmentBeanRegistered(ctx);
    assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
  }
View Full Code Here

  @Test
  public void classPathXmlApplicationContext() {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH);
    ctx.setEnvironment(prodEnv);
    ctx.refresh();

    assertEnvironmentBeanRegistered(ctx);
    assertHasEnvironment(ctx, prodEnv);
    assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
    assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
View Full Code Here

    // strange - FSXAC strips leading '/' unless prefixed with 'file:'
    ConfigurableApplicationContext ctx =
        new FileSystemXmlApplicationContext(new String[] {"file:" + tmpFile.getPath()}, false);
    ctx.setEnvironment(prodEnv);
    ctx.refresh();
    assertEnvironmentBeanRegistered(ctx);
    assertHasEnvironment(ctx, prodEnv);
    assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
    assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
View Full Code Here

  @Test
  public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.refresh();
    }

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo", "bar");
View Full Code Here

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo", "bar");
      try {
        ctx.refresh();
        fail("expected missing property exception");
      }
      catch (MissingRequiredPropertiesException ex) {
      }
    }
View Full Code Here

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo");
      ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue"));
      ctx.refresh(); // should succeed
    }
  }


  private DefaultListableBeanFactory newBeanFactoryWithEnvironmentAwareBean() {
View Full Code Here

    }
    { // ensure the same works for AbstractRefreshableApplicationContext impls too
      ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] { xmlLocation },
        false);
      context.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
      context.refresh();
      assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(true));
      context.close();
    }
  }
View Full Code Here

    void configure(Object beanInstance) {
        // check the ApplicationContext states first , and call the refresh if necessary
        if (((SpringCamelContext)getCamelContext()).getApplicationContext() instanceof ConfigurableApplicationContext) {
            ConfigurableApplicationContext context = (ConfigurableApplicationContext)((SpringCamelContext)getCamelContext()).getApplicationContext();
            if (!context.isActive()) {
                context.refresh();
            }
        }
        configurer.configureBean(beanId, beanInstance);
    }
   
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.