Search in sources :

Example 71 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class InjectAnnotationBeanPostProcessorTests method testAnnotatedDefaultConstructor.

@Test
public void testAnnotatedDefaultConstructor() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.addBeanPostProcessor(new AutowiredAnnotationBeanPostProcessor());
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedDefaultConstructorBean.class));
    assertNotNull(bf.getBean("annotatedBean"));
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 72 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class InjectAnnotationBeanPostProcessorTests method testNullableMethodInjectionWithBeanAvailable.

@Test
public void testNullableMethodInjectionWithBeanAvailable() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableMethodInjectionBean.class));
    bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
    NullableMethodInjectionBean bean = (NullableMethodInjectionBean) bf.getBean("annotatedBean");
    assertSame(bf.getBean("testBean"), bean.getTestBean());
    bf.destroySingletons();
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 73 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class InjectAnnotationBeanPostProcessorTests method testOptionalListMethodInjectionWithBeanNotAvailable.

@Test
public void testOptionalListMethodInjectionWithBeanNotAvailable() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class));
    OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
    assertFalse(bean.getTestBean().isPresent());
    bf.destroySingletons();
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 74 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class InjectAnnotationBeanPostProcessorTests method testOptionalMethodInjectionWithBeanNotAvailable.

@Test
public void testOptionalMethodInjectionWithBeanNotAvailable() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalMethodInjectionBean.class));
    OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean");
    assertFalse(bean.getTestBean().isPresent());
    bf.destroySingletons();
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 75 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class InjectAnnotationBeanPostProcessorTests method testOptionalFieldInjectionWithBeanNotAvailable.

@Test
public void testOptionalFieldInjectionWithBeanNotAvailable() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalFieldInjectionBean.class));
    OptionalFieldInjectionBean bean = (OptionalFieldInjectionBean) bf.getBean("annotatedBean");
    assertFalse(bean.getTestBean().isPresent());
    bf.destroySingletons();
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)652 Test (org.junit.Test)576 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)317 TestBean (org.springframework.tests.sample.beans.TestBean)249 ITestBean (org.springframework.tests.sample.beans.ITestBean)199 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)152 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)101 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)96 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)82 ClassPathResource (org.springframework.core.io.ClassPathResource)80 Properties (java.util.Properties)32 Before (org.junit.Before)27 BeanCreationException (org.springframework.beans.factory.BeanCreationException)26 ResourceTestBean (org.springframework.tests.sample.beans.ResourceTestBean)26 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)24 HashMap (java.util.HashMap)22 PropertiesBeanDefinitionReader (org.springframework.beans.factory.support.PropertiesBeanDefinitionReader)22 DependenciesBean (org.springframework.tests.sample.beans.DependenciesBean)17 ConstructorDependenciesBean (org.springframework.beans.factory.xml.ConstructorDependenciesBean)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)14