use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method genericsBasedInjectionWithScopedProxy.
@Test
public void genericsBasedInjectionWithScopedProxy() {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
beanFactory.registerBeanDefinition("annotatedBean", bd);
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ScopedProxyRepositoryConfiguration.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
beanFactory.freezeConfiguration();
RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertEquals("Repository<String>", bean.stringRepository.toString());
assertEquals("Repository<Integer>", bean.integerRepository.toString());
assertTrue(AopUtils.isCglibProxy(bean.stringRepository));
assertTrue(AopUtils.isCglibProxy(bean.integerRepository));
}
use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method genericsBasedInjection.
@Test
public void genericsBasedInjection() {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
beanFactory.registerBeanDefinition("annotatedBean", bd);
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryConfiguration.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertEquals("Repository<String>", bean.stringRepository.toString());
assertEquals("Repository<Integer>", bean.integerRepository.toString());
}
use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method genericsBasedInjectionWithImplTypeAtInjectionPoint.
@Test
public void genericsBasedInjectionWithImplTypeAtInjectionPoint() {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(bpp);
RootBeanDefinition bd = new RootBeanDefinition(SpecificRepositoryInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
beanFactory.registerBeanDefinition("annotatedBean", bd);
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(SpecificRepositoryConfiguration.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
beanFactory.preInstantiateSingletons();
SpecificRepositoryInjectionBean bean = (SpecificRepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertSame(beanFactory.getBean("genericRepo"), bean.genericRepository);
}
use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class SpringHandlerInstantiatorTests method setup.
@Before
public void setup() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("capitalizer", new RootBeanDefinition(Capitalizer.class));
instantiator = new SpringHandlerInstantiator(bf);
objectMapper = Jackson2ObjectMapperBuilder.json().handlerInstantiator(instantiator).build();
}
use of org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class SpringBeanAutowiringSupport method processInjectionBasedOnServletContext.
/**
* Process {@code @Autowired} injection for the given target object,
* based on the current root web application context as stored in the ServletContext.
* <p>Intended for use as a delegate.
* @param target the target object to process
* @param servletContext the ServletContext to find the Spring web application context in
* @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
*/
public static void processInjectionBasedOnServletContext(Object target, ServletContext servletContext) {
Assert.notNull(target, "Target object must not be null");
WebApplicationContext cc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
bpp.processInjection(target);
}
Aggregations