Search in sources :

Example 96 with XmlBeanDefinitionReader

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

the class FactoryBeanTests method testCircularReferenceWithPostProcessor.

@Test
public void testCircularReferenceWithPostProcessor() {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CIRCULAR_CONTEXT);
    CountingPostProcessor counter = new CountingPostProcessor();
    factory.addBeanPostProcessor(counter);
    BeanImpl1 impl1 = factory.getBean(BeanImpl1.class);
    assertNotNull(impl1);
    assertNotNull(impl1.getImpl2());
    assertNotNull(impl1.getImpl2());
    assertSame(impl1, impl1.getImpl2().getImpl1());
    assertEquals(1, counter.getCount("bean1"));
    assertEquals(1, counter.getCount("bean2"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 97 with XmlBeanDefinitionReader

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

the class TestNamespaceHandler method setUp.

@Before
public void setUp() throws Exception {
    NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
    this.beanFactory = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
    reader.setNamespaceHandlerResolver(resolver);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    reader.setEntityResolver(new DummySchemaResolver());
    reader.loadBeanDefinitions(getResource());
    this.beanFactory.refresh();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) NamespaceHandlerResolver(org.springframework.beans.factory.xml.NamespaceHandlerResolver) DefaultNamespaceHandlerResolver(org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultNamespaceHandlerResolver(org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver) Before(org.junit.Before)

Example 98 with XmlBeanDefinitionReader

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

the class GenericSqlQueryTests method setUp.

@Before
public void setUp() throws Exception {
    this.beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
    DataSource dataSource = mock(DataSource.class);
    this.connection = mock(Connection.class);
    this.preparedStatement = mock(PreparedStatement.class);
    this.resultSet = mock(ResultSet.class);
    given(dataSource.getConnection()).willReturn(connection);
    TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) beanFactory.getBean("dataSource");
    testDataSource.setTarget(dataSource);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ClassPathResource(org.springframework.core.io.ClassPathResource) DataSource(javax.sql.DataSource) TestDataSourceWrapper(org.springframework.jdbc.datasource.TestDataSourceWrapper) Before(org.junit.Before)

Example 99 with XmlBeanDefinitionReader

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

the class HybridContextLoader method loadBeanDefinitions.

@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
    // Order doesn't matter: <bean> always wins over @Bean.
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
    new AnnotatedBeanDefinitionReader(context).register(mergedConfig.getClasses());
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader)

Example 100 with XmlBeanDefinitionReader

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

the class TxNamespaceHandlerEventTests method setUp.

@Before
public void setUp() throws Exception {
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
    reader.setEventListener(this.eventListener);
    reader.loadBeanDefinitions(new ClassPathResource("txNamespaceHandlerTests.xml", getClass()));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

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