Search in sources :

Example 41 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class FactoryBeanTests method testAbstractFactoryBeanViaAnnotation.

@Test
public void testAbstractFactoryBeanViaAnnotation() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(ABSTRACT_CONTEXT);
    factory.getBeansWithAnnotation(Component.class);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 42 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class FactoryBeanTests method testFactoryBeanReturnsNull.

@Test
public void testFactoryBeanReturnsNull() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(RETURNS_NULL_CONTEXT);
    Object result = factory.getBean("factoryBean");
    assertNull(result);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 43 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class FactoryBeanTests method testAbstractFactoryBeanViaType.

@Test
public void testAbstractFactoryBeanViaType() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(ABSTRACT_CONTEXT);
    factory.getBeansOfType(AbstractFactoryBean.class);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 44 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class BeanFactoryGenericsTests method testGenericallyTypedSetOfIntegerBean.

@Test
public void testGenericallyTypedSetOfIntegerBean() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("genericBeanTests.xml", getClass()));
    GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean");
    assertEquals(new Integer(10), gb.getGenericProperty().iterator().next());
    assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next());
    assertEquals(new Integer(30), gb.getGenericListProperty().get(1).iterator().next());
}
Also used : GenericSetOfIntegerBean(org.springframework.tests.sample.beans.GenericSetOfIntegerBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 45 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.

the class AbstractXmlApplicationContext method loadBeanDefinitions.

/**
	 * Loads the bean definitions via an XmlBeanDefinitionReader.
	 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
	 * @see #initBeanDefinitionReader
	 * @see #loadBeanDefinitions
	 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(this.getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ResourceEntityResolver(org.springframework.beans.factory.xml.ResourceEntityResolver)

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