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);
}
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);
}
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;
}
}
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"));
}
}
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);
}
Aggregations