Search in sources :

Example 1 with BeanDefinitionReader

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

the class CollectionMergingTests method setUp.

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

Example 2 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByParameterName.

@Test
public void testQualifiedByParameterName() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByParameterNameTestBean.class);
    context.refresh();
    QualifiedByParameterNameTestBean testBean = (QualifiedByParameterNameTestBean) context.getBean("testBean");
    Person person = testBean.getLarry();
    assertEquals("LarryBean", person.getName());
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 3 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByValue.

@Test
public void testQualifiedByValue() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByValueTestBean.class);
    context.refresh();
    QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
    Person person = testBean.getLarry();
    assertEquals("Larry", person.getName());
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 4 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByParentValue.

@Test
public void testQualifiedByParentValue() {
    StaticApplicationContext parent = new StaticApplicationContext();
    GenericBeanDefinition parentLarry = new GenericBeanDefinition();
    parentLarry.setBeanClass(Person.class);
    parentLarry.getPropertyValues().add("name", "ParentLarry");
    parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
    parent.registerBeanDefinition("someLarry", parentLarry);
    GenericBeanDefinition otherLarry = new GenericBeanDefinition();
    otherLarry.setBeanClass(Person.class);
    otherLarry.getPropertyValues().add("name", "OtherLarry");
    otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
    parent.registerBeanDefinition("someOtherLarry", otherLarry);
    parent.refresh();
    StaticApplicationContext context = new StaticApplicationContext(parent);
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
    context.refresh();
    QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
    Person person = testBean.getLarry();
    assertEquals("ParentLarry", person.getName());
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) AutowireCandidateQualifier(org.springframework.beans.factory.support.AutowireCandidateQualifier) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AutowireCandidateQualifier(org.springframework.beans.factory.support.AutowireCandidateQualifier) Test(org.junit.Test)

Example 5 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByBeanName.

@Test
public void testQualifiedByBeanName() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByBeanNameTestBean.class);
    context.refresh();
    QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
    Person person = testBean.getLarry();
    assertEquals("LarryBean", person.getName());
    assertTrue(testBean.myProps != null && testBean.myProps.isEmpty());
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Aggregations

BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)16 Test (org.junit.Test)14 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)13 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 QualifierAnnotationAutowireCandidateResolver (org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver)1 GroovyBeanDefinitionReader (org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader)1 AbstractBeanDefinitionReader (org.springframework.beans.factory.support.AbstractBeanDefinitionReader)1 AutowireCandidateQualifier (org.springframework.beans.factory.support.AutowireCandidateQualifier)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1