Java Code Examples for org.springframework.context.support.GenericXmlApplicationContext#load()

The following examples show how to use org.springframework.context.support.GenericXmlApplicationContext#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@Test
public void configuredThroughNamespace() {
	GenericXmlApplicationContext context = new GenericXmlApplicationContext();
	context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
	context.refresh();
	ITestBean testBean = context.getBean("target", ITestBean.class);
	testBean.test();
	testBean.await(3000);
	Thread asyncThread = testBean.getThread();
	assertTrue(asyncThread.getName().startsWith("testExecutor"));

	TestableAsyncUncaughtExceptionHandler exceptionHandler =
			context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
	assertFalse("handler should not have been called yet", exceptionHandler.isCalled());

	testBean.failWithVoid();
	exceptionHandler.await(3000);
	Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
	exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
	context.close();
}
 
Example 2
Source File: AsyncAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void configuredThroughNamespace() {
	GenericXmlApplicationContext context = new GenericXmlApplicationContext();
	context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
	context.refresh();
	ITestBean testBean = context.getBean("target", ITestBean.class);
	testBean.test();
	testBean.await(3000);
	Thread asyncThread = testBean.getThread();
	assertTrue(asyncThread.getName().startsWith("testExecutor"));

	TestableAsyncUncaughtExceptionHandler exceptionHandler =
			context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
	assertFalse("handler should not have been called yet", exceptionHandler.isCalled());

	testBean.failWithVoid();
	exceptionHandler.await(3000);
	Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
	exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
	context.close();
}
 
Example 3
Source File: AsyncAnnotationBeanPostProcessorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void configuredThroughNamespace() {
	GenericXmlApplicationContext context = new GenericXmlApplicationContext();
	context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
	context.refresh();
	ITestBean testBean = context.getBean("target", ITestBean.class);
	testBean.test();
	testBean.await(3000);
	Thread asyncThread = testBean.getThread();
	assertTrue(asyncThread.getName().startsWith("testExecutor"));

	TestableAsyncUncaughtExceptionHandler exceptionHandler =
			context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
	assertFalse("handler should not have been called yet", exceptionHandler.isCalled());

	testBean.failWithVoid();
	exceptionHandler.await(3000);
	Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
	exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
	context.close();
}
 
Example 4
Source File: ContextNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void propertyPlaceholderEnvironmentProperties() {
	MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
	GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
	applicationContext.setEnvironment(env);
	applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
	applicationContext.refresh();
	assertEquals("spam", applicationContext.getBean("string"));
	assertEquals("none", applicationContext.getBean("fallback"));
}
 
Example 5
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void genericXmlApplicationContext() {
	GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
	assertHasStandardEnvironment(ctx);
	ctx.setEnvironment(prodEnv);
	ctx.load(XML_PATH);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 6
Source File: ContextNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void propertyPlaceholderEnvironmentProperties() throws Exception {
	MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
	GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
	applicationContext.setEnvironment(env);
	applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
	applicationContext.refresh();
	assertEquals("spam", applicationContext.getBean("string"));
	assertEquals("none", applicationContext.getBean("fallback"));
}
 
Example 7
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void genericXmlApplicationContext() {
	GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
	assertHasStandardEnvironment(ctx);
	ctx.setEnvironment(prodEnv);
	ctx.load(XML_PATH);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 8
Source File: ContextNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void propertyPlaceholderEnvironmentProperties() throws Exception {
	MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
	GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
	applicationContext.setEnvironment(env);
	applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
	applicationContext.refresh();
	Map<String, PlaceholderConfigurerSupport> beans = applicationContext
			.getBeansOfType(PlaceholderConfigurerSupport.class);
	assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty());
	assertEquals("spam", applicationContext.getBean("string"));
	assertEquals("none", applicationContext.getBean("fallback"));
}
 
Example 9
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void genericXmlApplicationContext() {
	GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
	assertHasStandardEnvironment(ctx);
	ctx.setEnvironment(prodEnv);
	ctx.load(XML_PATH);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 10
Source File: DynamicInstrumentationLoader.java    From invesdwin-instrument with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static synchronized GenericXmlApplicationContext initLoadTimeWeavingContext() {
    org.assertj.core.api.Assertions.assertThat(isInitialized()).isTrue();
    if (ltwCtx == null) {
        final GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        ctx.load(new ClassPathResource("/META-INF/ctx.spring.weaving.xml"));
        ctx.refresh();
        ltwCtx = ctx;
    }
    return ltwCtx;
}
 
Example 11
Source File: SpringContextBuilder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
private AbstractApplicationContext createMainContext(final boolean allowBeanOverride) {
  final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
  if (activeProfiles != null && !activeProfiles.isEmpty()) {
    context.getEnvironment().setActiveProfiles(activeProfiles);
  }
  context.setAllowBeanDefinitionOverriding(allowBeanOverride);
  context.load(mainParams.path);
  context.refresh();
  return context;
}
 
Example 12
Source File: SpringContextBuilder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
public AbstractApplicationContext createSubContext(final AbstractApplicationContext parent, final String path, final boolean allowBeanOverride) {
  final GenericXmlApplicationContext subContext = new GenericXmlApplicationContext();
  subContext.setParent(parent);
  subContext.setAllowBeanDefinitionOverriding(allowBeanOverride);
  subContext.load(path);
  subContext.refresh();
  return subContext;
}