beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
@Override @Nullable public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { return (isLazy(descriptor) ? buildLazyResolutionProxy(descriptor, beanName) : null); }
protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final @Nullable String beanName) { Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory, "BeanFactory needs to be a DefaultListableBeanFactory"); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory(); TargetSource ts = new TargetSource() { @Override
@Override protected boolean isLazy(DependencyDescriptor descriptor) { Class<?> type = descriptor.getDependencyType(); RepositoryConfiguration<?> configuration = configurations.get(type.getName()); if (configuration == null) { return super.isLazy(descriptor); } boolean lazyInit = configuration.isLazyInit(); if (lazyInit) { LOG.debug("Creating lazy injection proxy for {}…", configuration.getRepositoryInterface()); } return lazyInit; } }
protected boolean isLazy(DependencyDescriptor descriptor, String beanName) { Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory, "BeanFactory needs to be a DefaultListableBeanFactory"); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory(); try { beanFactory.doResolveDependency(descriptor, beanName, null, null); } catch (NoSuchBeanDefinitionException e) { return true; } return super.isLazy(descriptor); }
beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
@Override @Nullable public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { return (isLazy(descriptor) ? buildLazyResolutionProxy(descriptor, beanName) : null); }
protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final @Nullable String beanName) { Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory, "BeanFactory needs to be a DefaultListableBeanFactory"); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory(); TargetSource ts = new TargetSource() { @Override
@Test public void testLazyResourceInjectionWithNonExistingTarget() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(FieldResourceInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); FieldResourceInjectionBean bean = (FieldResourceInjectionBean) bf.getBean("annotatedBean"); assertNotNull(bean.getTestBean()); try { bean.getTestBean().getName(); fail("Should have thrown NoSuchBeanDefinitionException"); } catch (NoSuchBeanDefinitionException ex) { // expected } }
@Override @Nullable public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { return (isLazy(descriptor) ? buildLazyResolutionProxy(descriptor, beanName) : null); }
protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final @Nullable String beanName) { Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory, "BeanFactory needs to be a DefaultListableBeanFactory"); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory(); TargetSource ts = new TargetSource() { @Override
@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()); assertNotNull(bean.getTestBeans()); assertTrue(bean.getTestBeans().isEmpty()); try { bean.getTestBean().getName(); fail("Should have thrown NoSuchBeanDefinitionException"); } catch (NoSuchBeanDefinitionException ex) { // expected } }
@Override protected DefaultListableBeanFactory createBeanFactory() { // Copy all postProcessors defined in the defaultMuleConfig so that they get applied to the child container DefaultListableBeanFactory beanFactory = new ObjectProviderAwareBeanFactory(getInternalParentBeanFactory()); beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver()); beanFactory.setInstantiationStrategy(new LaxInstantiationStrategyWrapper(new CglibSubclassingInstantiationStrategy(), optionalObjectsController)); return beanFactory; }
beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
@Override protected DefaultListableBeanFactory createBeanFactory() { // Copy all postProcessors defined in the defaultMuleConfig so that they get applied to the child container DefaultListableBeanFactory beanFactory = new ObjectProviderAwareBeanFactory(getInternalParentBeanFactory()); beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver()); beanFactory.setInstantiationStrategy(new LaxInstantiationStrategyWrapper(new CglibSubclassingInstantiationStrategy(), optionalObjectsController)); return beanFactory; }
@Override protected DefaultListableBeanFactory createBeanFactory() { //Copy all postProcessors defined in the defaultMuleConfig so that they get applied to the child container DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(getInternalParentBeanFactory()); beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver()); beanFactory.setInstantiationStrategy(new LaxInstantiationStrategyWrapper(new CglibSubclassingInstantiationStrategy(), optionalObjectsController)); return beanFactory; }