use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ConfigurationClassAspectIntegrationTests method assertAdviceWasApplied.
private void assertAdviceWasApplied(Class<?> configClass) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
GenericApplicationContext ctx = new GenericApplicationContext(factory);
ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass));
ctx.refresh();
TestBean testBean = ctx.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("name"));
testBean.absquatulate();
assertThat(testBean.getName(), equalTo("advisedName"));
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class AutowiredConfigurationTests method testCustomPropertiesWithGenericContext.
@Test
public void testCustomPropertiesWithGenericContext() throws IOException {
GenericApplicationContext context = new GenericApplicationContext();
new XmlBeanDefinitionReader(context).loadBeanDefinitions(new ClassPathResource("AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class));
context.refresh();
TestBean testBean = context.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("localhost"));
assertThat(testBean.getAge(), equalTo(contentLength()));
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ClassPathXmlApplicationContextTests method testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull.
@Test
public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setClassLoader(null);
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass()));
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass()));
ctx.refresh();
assertEquals(ObjectUtils.identityToString(ctx), ctx.getId());
assertEquals(ObjectUtils.identityToString(ctx), ctx.getDisplayName());
assertTrue(ctx.containsBean("service"));
assertTrue(ctx.containsBean("logicOne"));
assertTrue(ctx.containsBean("logicTwo"));
ctx.close();
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ClassPathXmlApplicationContextTests method testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId.
@Test
public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setId("testContext");
ctx.setDisplayName("Test Context");
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass()));
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass()));
reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass()));
ctx.refresh();
assertEquals("testContext", ctx.getId());
assertEquals("Test Context", ctx.getDisplayName());
assertTrue(ctx.containsBean("service"));
assertTrue(ctx.containsBean("logicOne"));
assertTrue(ctx.containsBean("logicTwo"));
ctx.close();
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class AbstractMBeanServerTests method loadContext.
protected ConfigurableApplicationContext loadContext(String configLocation) {
GenericApplicationContext ctx = new GenericApplicationContext();
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(configLocation);
ctx.getDefaultListableBeanFactory().registerSingleton("server", this.server);
ctx.refresh();
return ctx;
}
Aggregations