Search in sources :

Example 56 with XmlBeanDefinitionReader

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"));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConfigurationClassPostProcessor(org.springframework.context.annotation.ConfigurationClassPostProcessor) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 57 with XmlBeanDefinitionReader

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()));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 58 with XmlBeanDefinitionReader

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();
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 59 with XmlBeanDefinitionReader

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();
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 60 with XmlBeanDefinitionReader

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;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)

Aggregations

XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)152 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)82 Test (org.junit.Test)80 ClassPathResource (org.springframework.core.io.ClassPathResource)62 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)38 Before (org.junit.Before)30 ITestBean (org.springframework.tests.sample.beans.ITestBean)18 TestBean (org.springframework.tests.sample.beans.TestBean)11 BeansException (org.springframework.beans.BeansException)9 Resource (org.springframework.core.io.Resource)8 UrlResource (org.springframework.core.io.UrlResource)8 URL (java.net.URL)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)6 HashMap (java.util.HashMap)5 Person (org.springframework.tests.sample.beans.Person)5 ArrayList (java.util.ArrayList)4 BeanCreationException (org.springframework.beans.factory.BeanCreationException)4 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)4 ResourceEntityResolver (org.springframework.beans.factory.xml.ResourceEntityResolver)4