Search in sources :

Example 11 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testNonQualifiedFieldFails.

@Test
public void testNonQualifiedFieldFails() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", NonQualifiedTestBean.class);
    try {
        context.refresh();
        fail("Should have thrown a BeanCreationException");
    } catch (BeanCreationException e) {
        assertTrue(e.getMessage().contains("found 6"));
    }
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) BeanCreationException(org.springframework.beans.factory.BeanCreationException) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 12 with BeanDefinitionReader

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

the class CustomAutowireConfigurerTests method testCustomResolver.

@Test
public void testCustomResolver() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
    reader.loadBeanDefinitions(CONTEXT);
    CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
    CustomResolver customResolver = new CustomResolver();
    bf.setAutowireCandidateResolver(customResolver);
    cac.postProcessBeanFactory(bf);
    TestBean testBean = (TestBean) bf.getBean("testBean");
    assertEquals("#1!", testBean.getName());
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 13 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByAttributesFailsWithoutCustomQualifierRegistered.

@Test
public void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByAttributesTestBean.class);
    try {
        context.refresh();
        fail("should have thrown a BeanCreationException");
    } catch (BeanCreationException e) {
        assertTrue(e.getMessage().contains("found 6"));
    }
}
Also used : BeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionReader) BeanCreationException(org.springframework.beans.factory.BeanCreationException) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 14 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByAnnotation.

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

Example 15 with BeanDefinitionReader

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

the class QualifierAnnotationTests method testQualifiedByAnnotationValue.

@Test
public void testQualifiedByAnnotationValue() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByAnnotationValueTestBean.class);
    context.refresh();
    QualifiedByAnnotationValueTestBean testBean = (QualifiedByAnnotationValueTestBean) context.getBean("testBean");
    Person person = testBean.getLarry();
    assertEquals("LarrySpecial", 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