Search in sources :

Example 6 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByAttributesWithCustomQualifierRegistered.

@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver) context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
    resolver.addQualifierType(MultipleAttributeQualifier.class);
    context.registerSingleton("testBean", MultiQualifierClient.class);
    context.refresh();
    MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");
    assertNotNull(testBean.factoryTheta);
    assertNotNull(testBean.implTheta);
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) QualifierAnnotationAutowireCandidateResolver(org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver) Test(org.junit.Test)

Example 7 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByCustomValue.

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

Example 8 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testInterfaceWithOneQualifiedFactoryAndOneQualifiedBean.

@Test
public void testInterfaceWithOneQualifiedFactoryAndOneQualifiedBean() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 9 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByFieldName.

@Test
public void testQualifiedByFieldName() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByFieldNameTestBean.class);
    context.refresh();
    QualifiedByFieldNameTestBean testBean = (QualifiedByFieldNameTestBean) 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 10 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByAlias.

@Test
public void testQualifiedByAlias() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByAliasTestBean.class);
    context.refresh();
    QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
    Person person = testBean.getStooge();
    assertEquals("LarryBean", person.getName());
}
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