Search in sources :

Example 6 with AutowiredAnnotationBeanPostProcessor

use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.

the class ConfigurationClassPostProcessorTests method testConfigWithDefaultMethodsUsingAsm.

@Test
public void testConfigWithDefaultMethodsUsingAsm() {
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(beanFactory);
    beanFactory.addBeanPostProcessor(bpp);
    beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
    beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ConcreteConfigWithDefaultMethods.class.getName()));
    beanFactory.registerBeanDefinition("serviceBeanProvider", new RootBeanDefinition(ServiceBeanProvider.class.getName()));
    new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
    beanFactory.preInstantiateSingletons();
    beanFactory.getBean(ServiceBean.class);
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 7 with AutowiredAnnotationBeanPostProcessor

use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.

the class ConfigurationClassPostProcessorTests method testConfigWithDefaultMethods.

@Test
public void testConfigWithDefaultMethods() {
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(beanFactory);
    beanFactory.addBeanPostProcessor(bpp);
    beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
    beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ConcreteConfigWithDefaultMethods.class));
    beanFactory.registerBeanDefinition("serviceBeanProvider", new RootBeanDefinition(ServiceBeanProvider.class));
    new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
    beanFactory.preInstantiateSingletons();
    beanFactory.getBean(ServiceBean.class);
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 8 with AutowiredAnnotationBeanPostProcessor

use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.

the class LazyAutowiredAnnotationBeanPostProcessorTests method testLazyOptionalResourceInjectionWithNonExistingTarget.

@Test
public void testLazyOptionalResourceInjectionWithNonExistingTarget() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    RootBeanDefinition bd = new RootBeanDefinition(OptionalFieldResourceInjectionBean.class);
    bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    bf.registerBeanDefinition("annotatedBean", bd);
    OptionalFieldResourceInjectionBean bean = (OptionalFieldResourceInjectionBean) bf.getBean("annotatedBean");
    assertNotNull(bean.getTestBean());
    try {
        bean.getTestBean().getName();
        fail("Should have thrown NoSuchBeanDefinitionException");
    } catch (NoSuchBeanDefinitionException ex) {
    // expected;
    }
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 9 with AutowiredAnnotationBeanPostProcessor

use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.

the class ConfigurationClassPostProcessorTests method testCircularDependency.

@Test
public void testCircularDependency() {
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(beanFactory);
    beanFactory.addBeanPostProcessor(bpp);
    beanFactory.registerBeanDefinition("configClass1", new RootBeanDefinition(A.class));
    beanFactory.registerBeanDefinition("configClass2", new RootBeanDefinition(AStrich.class));
    new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
    try {
        beanFactory.preInstantiateSingletons();
        fail("Should have thrown BeanCreationException");
    } catch (BeanCreationException ex) {
        assertTrue(ex.getMessage().contains("Circular reference"));
    }
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) BeanCreationException(org.springframework.beans.factory.BeanCreationException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 10 with AutowiredAnnotationBeanPostProcessor

use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.

the class ConfigurationClassPostProcessorTests method scopedProxyTargetMarkedAsNonAutowireCandidate.

@Test
public void scopedProxyTargetMarkedAsNonAutowireCandidate() {
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(beanFactory);
    beanFactory.addBeanPostProcessor(bpp);
    beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class));
    beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class));
    ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
    pp.postProcessBeanFactory(beanFactory);
    ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean;
    assertTrue(injected instanceof ScopedObject);
    assertSame(beanFactory.getBean("scopedClass"), injected);
    assertSame(beanFactory.getBean(ITestBean.class), injected);
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) ITestBean(org.springframework.tests.sample.beans.ITestBean) ScopedObject(org.springframework.aop.scope.ScopedObject) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

AutowiredAnnotationBeanPostProcessor (org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 Test (org.junit.Test)13 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)3 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 Before (org.junit.Before)1 ScopedObject (org.springframework.aop.scope.ScopedObject)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1