Java Code Examples for org.springframework.beans.factory.support.DefaultListableBeanFactory#setAutowireCandidateResolver()
The following examples show how to use
org.springframework.beans.factory.support.DefaultListableBeanFactory#setAutowireCandidateResolver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LazyAutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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; } }
Example 2
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testGenericsBasedInjectionIntoMatchingTypeVariable() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(GenericInterface1Impl.class); bd.setFactoryMethodName("create"); bf.registerBeanDefinition("bean1", bd); bf.registerBeanDefinition("bean2", new RootBeanDefinition(GenericInterface2Impl.class)); GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1"); GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2"); assertSame(bean2, bean1.gi2); }
Example 3
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testGenericsBasedInjectionIntoUnresolvedTypeVariable() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(GenericInterface1Impl.class); bd.setFactoryMethodName("createPlain"); bf.registerBeanDefinition("bean1", bd); bf.registerBeanDefinition("bean2", new RootBeanDefinition(GenericInterface2Impl.class)); GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1"); GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2"); assertSame(bean2, bean1.gi2); }
Example 4
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test @Ignore // SPR-11521 public void testGenericsBasedInjectionIntoTypeVariableSelectingBestMatchAgainstFactoryMethodSignature() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(GenericInterface1Impl.class); bd.setFactoryMethodName("createErased"); bf.registerBeanDefinition("bean1", bd); bf.registerBeanDefinition("bean2", new RootBeanDefinition(GenericInterface2Impl.class)); bf.registerBeanDefinition("bean2a", new RootBeanDefinition(ReallyGenericInterface2Impl.class)); bf.registerBeanDefinition("bean2b", new RootBeanDefinition(PlainGenericInterface2Impl.class)); GenericInterface1Impl bean1 = (GenericInterface1Impl) bf.getBean("bean1"); GenericInterface2Impl bean2 = (GenericInterface2Impl) bf.getBean("bean2"); assertSame(bean2, bean1.gi2); }
Example 5
Source File: InjectAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testObjectFactoryMethodInjectionIntoPrototypeBean() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierMethodInjectionBean.class); annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean")); bf.registerBeanDefinition("testBean", bd); bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class)); ObjectFactoryQualifierMethodInjectionBean bean = (ObjectFactoryQualifierMethodInjectionBean) bf.getBean("annotatedBean"); assertSame(bf.getBean("testBean"), bean.getTestBean()); ObjectFactoryQualifierMethodInjectionBean anotherBean = (ObjectFactoryQualifierMethodInjectionBean) bf.getBean("annotatedBean"); assertNotSame(anotherBean, bean); assertSame(bf.getBean("testBean"), bean.getTestBean()); }
Example 6
Source File: LazyAutowiredAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 6 votes |
@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 } }
Example 7
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testGenericsBasedFactoryBeanInjectionWithSingletonBean() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryFactoryBeanInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); bf.registerSingleton("repoFactoryBean", new RepositoryFactoryBean<>()); RepositoryFactoryBeanInjectionBean bean = (RepositoryFactoryBeanInjectionBean) bf.getBean("annotatedBean"); RepositoryFactoryBean repoFactoryBean = bf.getBean("&repoFactoryBean", RepositoryFactoryBean.class); assertSame(repoFactoryBean, bean.repositoryFactoryBean); }
Example 8
Source File: AutowiredAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() { bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); }
Example 9
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testGenericsBasedFieldInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryFieldInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); StringRepository sr = new StringRepository(); bf.registerSingleton("stringRepo", sr); IntegerRepository ir = new IntegerRepository(); bf.registerSingleton("integerRepo", ir); RepositoryFieldInjectionBean bean = (RepositoryFieldInjectionBean) bf.getBean("annotatedBean"); assertSame(sr, bean.stringRepository); assertSame(ir, bean.integerRepository); assertSame(1, bean.stringRepositoryArray.length); assertSame(1, bean.integerRepositoryArray.length); assertSame(sr, bean.stringRepositoryArray[0]); assertSame(ir, bean.integerRepositoryArray[0]); assertSame(1, bean.stringRepositoryList.size()); assertSame(1, bean.integerRepositoryList.size()); assertSame(sr, bean.stringRepositoryList.get(0)); assertSame(ir, bean.integerRepositoryList.get(0)); assertSame(1, bean.stringRepositoryMap.size()); assertSame(1, bean.integerRepositoryMap.size()); assertSame(sr, bean.stringRepositoryMap.get("stringRepo")); assertSame(ir, bean.integerRepositoryMap.get("integerRepo")); }
Example 10
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testGenericsBasedFieldInjectionWithSimpleMatch() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryFieldInjectionBeanWithSimpleMatch.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); bf.registerSingleton("repo", new StringRepository()); RepositoryFieldInjectionBeanWithSimpleMatch bean = (RepositoryFieldInjectionBeanWithSimpleMatch) bf.getBean("annotatedBean"); Repository repo = bf.getBean("repo", Repository.class); assertSame(repo, bean.repository); assertSame(repo, bean.stringRepository); assertSame(1, bean.repositoryArray.length); assertSame(1, bean.stringRepositoryArray.length); assertSame(repo, bean.repositoryArray[0]); assertSame(repo, bean.stringRepositoryArray[0]); assertSame(1, bean.repositoryList.size()); assertSame(1, bean.stringRepositoryList.size()); assertSame(repo, bean.repositoryList.get(0)); assertSame(repo, bean.stringRepositoryList.get(0)); assertSame(1, bean.repositoryMap.size()); assertSame(1, bean.stringRepositoryMap.size()); assertSame(repo, bean.repositoryMap.get("repo")); assertSame(repo, bean.stringRepositoryMap.get("repo")); }
Example 11
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testGenericsBasedConstructorInjectionWithNonTypedTarget() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryConstructorInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); GenericRepository gr = new GenericRepository(); bf.registerSingleton("genericRepo", gr); RepositoryConstructorInjectionBean bean = (RepositoryConstructorInjectionBean) bf.getBean("annotatedBean"); assertSame(gr, bean.stringRepository); assertSame(gr, bean.integerRepository); assertSame(1, bean.stringRepositoryArray.length); assertSame(1, bean.integerRepositoryArray.length); assertSame(gr, bean.stringRepositoryArray[0]); assertSame(gr, bean.integerRepositoryArray[0]); assertSame(1, bean.stringRepositoryList.size()); assertSame(1, bean.integerRepositoryList.size()); assertSame(gr, bean.stringRepositoryList.get(0)); assertSame(gr, bean.integerRepositoryList.get(0)); assertSame(1, bean.stringRepositoryMap.size()); assertSame(1, bean.integerRepositoryMap.size()); assertSame(gr, bean.stringRepositoryMap.get("genericRepo")); assertSame(gr, bean.integerRepositoryMap.get("genericRepo")); }
Example 12
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testCircularTypeReference() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.registerBeanDefinition("bean1", new RootBeanDefinition(StockServiceImpl.class)); bf.registerBeanDefinition("bean2", new RootBeanDefinition(StockMovementDaoImpl.class)); bf.registerBeanDefinition("bean3", new RootBeanDefinition(StockMovementImpl.class)); bf.registerBeanDefinition("bean4", new RootBeanDefinition(StockMovementInstructionImpl.class)); StockServiceImpl service = bf.getBean(StockServiceImpl.class); assertSame(bf.getBean(StockMovementDaoImpl.class), service.stockMovementDao); }
Example 13
Source File: InjectAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() { bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); }
Example 14
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testGenericsBasedFieldInjectionWithQualifiers() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryFieldInjectionBeanWithQualifiers.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); StringRepository sr = new StringRepository(); bf.registerSingleton("stringRepo", sr); IntegerRepository ir = new IntegerRepository(); bf.registerSingleton("integerRepo", ir); RepositoryFieldInjectionBeanWithQualifiers bean = (RepositoryFieldInjectionBeanWithQualifiers) bf.getBean("annotatedBean"); assertSame(sr, bean.stringRepository); assertSame(ir, bean.integerRepository); assertSame(1, bean.stringRepositoryArray.length); assertSame(1, bean.integerRepositoryArray.length); assertSame(sr, bean.stringRepositoryArray[0]); assertSame(ir, bean.integerRepositoryArray[0]); assertSame(1, bean.stringRepositoryList.size()); assertSame(1, bean.integerRepositoryList.size()); assertSame(sr, bean.stringRepositoryList.get(0)); assertSame(ir, bean.integerRepositoryList.get(0)); assertSame(1, bean.stringRepositoryMap.size()); assertSame(1, bean.integerRepositoryMap.size()); assertSame(sr, bean.stringRepositoryMap.get("stringRepo")); assertSame(ir, bean.integerRepositoryMap.get("integerRepo")); }
Example 15
Source File: InjectAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() { bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); }
Example 16
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() { bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); }
Example 17
Source File: CustomAutowireConfigurerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCustomResolver() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml")); CustomAutowireConfigurer cac = new CustomAutowireConfigurer(); CustomResolver customResolver = new CustomResolver(); bf.setAutowireCandidateResolver(customResolver); cac.postProcessBeanFactory(bf); TestBean testBean = (TestBean) bf.getBean("testBean"); assertEquals("#1!", testBean.getName()); }
Example 18
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testGenericsBasedConstructorInjectionWithMixedTargets() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryConstructorInjectionBean.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); StringRepository sr = new StringRepository(); bf.registerSingleton("stringRepo", sr); GenericRepository gr = new GenericRepositorySubclass(); bf.registerSingleton("genericRepo", gr); RepositoryConstructorInjectionBean bean = (RepositoryConstructorInjectionBean) bf.getBean("annotatedBean"); assertSame(sr, bean.stringRepository); assertSame(gr, bean.integerRepository); assertSame(1, bean.stringRepositoryArray.length); assertSame(1, bean.integerRepositoryArray.length); assertSame(sr, bean.stringRepositoryArray[0]); assertSame(gr, bean.integerRepositoryArray[0]); assertSame(1, bean.stringRepositoryList.size()); assertSame(1, bean.integerRepositoryList.size()); assertSame(sr, bean.stringRepositoryList.get(0)); assertSame(gr, bean.integerRepositoryList.get(0)); assertSame(1, bean.stringRepositoryMap.size()); assertSame(1, bean.integerRepositoryMap.size()); assertSame(sr, bean.stringRepositoryMap.get("stringRepo")); assertSame(gr, bean.integerRepositoryMap.get("genericRepo")); }
Example 19
Source File: AutowiredAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testGenericsBasedMethodInjectionWithSubstitutedVariables() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); RootBeanDefinition bd = new RootBeanDefinition(RepositoryMethodInjectionBeanWithSubstitutedVariables.class); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); StringRepository sr = new StringRepository(); bf.registerSingleton("stringRepo", sr); IntegerRepository ir = new IntegerRepository(); bf.registerSingleton("integerRepo", ir); RepositoryMethodInjectionBeanWithSubstitutedVariables bean = (RepositoryMethodInjectionBeanWithSubstitutedVariables) bf.getBean("annotatedBean"); assertSame(sr, bean.stringRepository); assertSame(ir, bean.integerRepository); assertSame(1, bean.stringRepositoryArray.length); assertSame(1, bean.integerRepositoryArray.length); assertSame(sr, bean.stringRepositoryArray[0]); assertSame(ir, bean.integerRepositoryArray[0]); assertSame(1, bean.stringRepositoryList.size()); assertSame(1, bean.integerRepositoryList.size()); assertSame(sr, bean.stringRepositoryList.get(0)); assertSame(ir, bean.integerRepositoryList.get(0)); assertSame(1, bean.stringRepositoryMap.size()); assertSame(1, bean.integerRepositoryMap.size()); assertSame(sr, bean.stringRepositoryMap.get("stringRepo")); assertSame(ir, bean.integerRepositoryMap.get("integerRepo")); }
Example 20
Source File: StatefulFactory.java From statefulj with Apache License 2.0 | 4 votes |
public void postProcessBeanFactory(final ConfigurableListableBeanFactory reg) throws BeansException { DefaultListableBeanFactory bf = (DefaultListableBeanFactory) reg; bf.setAutowireCandidateResolver(new FSMAnnotationResolver()); }