Search in sources :

Example 6 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 7 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 8 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 9 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 10 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)138 Test (org.junit.Test)79 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)74 ClassPathResource (org.springframework.core.io.ClassPathResource)59 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)36 Before (org.junit.Before)24 ITestBean (org.springframework.tests.sample.beans.ITestBean)18 TestBean (org.springframework.tests.sample.beans.TestBean)11 BeansException (org.springframework.beans.BeansException)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 Resource (org.springframework.core.io.Resource)7 UrlResource (org.springframework.core.io.UrlResource)7 URL (java.net.URL)6 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 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)4 Map (java.util.Map)3