Java Code Examples for org.springframework.beans.factory.support.RootBeanDefinition#setUniqueFactoryMethodName()

The following examples show how to use org.springframework.beans.factory.support.RootBeanDefinition#setUniqueFactoryMethodName() . 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: AutowiredAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testConstructorInjectionWithCustomMapAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(CustomMapConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbm = new RootBeanDefinition(CustomCollectionFactoryMethods.class);
	tbm.setUniqueFactoryMethodName("testBeanMap");
	bf.registerBeanDefinition("myTestBeanMap", tbm);
	bf.registerSingleton("testBean1", new TestBean());
	bf.registerSingleton("testBean2", new TestBean());

	CustomMapConstructorInjectionBean bean = (CustomMapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
	bean = (CustomMapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
}
 
Example 2
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testConstructorInjectionWithCustomMapAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(CustomMapConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbm = new RootBeanDefinition(CustomCollectionFactoryMethods.class);
	tbm.setUniqueFactoryMethodName("testBeanMap");
	bf.registerBeanDefinition("myTestBeanMap", tbm);
	bf.registerSingleton("testBean1", new TestBean());
	bf.registerSingleton("testBean2", new TestBean());

	CustomMapConstructorInjectionBean bean = (CustomMapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
	bean = (CustomMapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
}
 
Example 3
Source File: BindingBeanDefinitionRegistryUtils.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
private static void registerBindingTargetBeanDefinition(
		Class<? extends Annotation> qualifier, String qualifierValue, String name,
		String bindingTargetInterfaceBeanName,
		String bindingTargetInterfaceMethodName, BeanDefinitionRegistry registry) {

	if (registry.containsBeanDefinition(name)) {
		throw new BeanDefinitionStoreException(bindingTargetInterfaceBeanName, name,
				"bean definition with this name already exists - "
						+ registry.getBeanDefinition(name));
	}

	RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
	rootBeanDefinition.setFactoryBeanName(bindingTargetInterfaceBeanName);
	rootBeanDefinition.setUniqueFactoryMethodName(bindingTargetInterfaceMethodName);
	rootBeanDefinition
			.addQualifier(new AutowireCandidateQualifier(qualifier, qualifierValue));
	registry.registerBeanDefinition(name, rootBeanDefinition);
}
 
Example 4
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testConstructorInjectionWithPlainMapAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(MapConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbm = new RootBeanDefinition(CollectionFactoryMethods.class);
	tbm.setUniqueFactoryMethodName("testBeanMap");
	bf.registerBeanDefinition("myTestBeanMap", tbm);
	bf.registerSingleton("otherMap", new HashMap<>());

	MapConstructorInjectionBean bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
	bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
}
 
Example 5
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testConstructorInjectionWithPlainSetAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(SetConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbs = new RootBeanDefinition(CollectionFactoryMethods.class);
	tbs.setUniqueFactoryMethodName("testBeanSet");
	bf.registerBeanDefinition("myTestBeanSet", tbs);
	bf.registerSingleton("otherSet", new HashSet<>());

	SetConstructorInjectionBean bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
	bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
}
 
Example 6
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testConstructorInjectionWithCustomSetAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(CustomSetConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbs = new RootBeanDefinition(CustomCollectionFactoryMethods.class);
	tbs.setUniqueFactoryMethodName("testBeanSet");
	bf.registerBeanDefinition("myTestBeanSet", tbs);

	CustomSetConstructorInjectionBean bean = (CustomSetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
	bean = (CustomSetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
}
 
Example 7
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testConstructorInjectionWithPlainMapAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(MapConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbm = new RootBeanDefinition(CollectionFactoryMethods.class);
	tbm.setUniqueFactoryMethodName("testBeanMap");
	bf.registerBeanDefinition("myTestBeanMap", tbm);
	bf.registerSingleton("otherMap", new HashMap<>());

	MapConstructorInjectionBean bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
	bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanMap"), bean.getTestBeanMap());
}
 
Example 8
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testConstructorInjectionWithPlainSetAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(SetConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbs = new RootBeanDefinition(CollectionFactoryMethods.class);
	tbs.setUniqueFactoryMethodName("testBeanSet");
	bf.registerBeanDefinition("myTestBeanSet", tbs);
	bf.registerSingleton("otherSet", new HashSet<>());

	SetConstructorInjectionBean bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
	bean = (SetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
}
 
Example 9
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testConstructorInjectionWithCustomSetAsBean() {
	RootBeanDefinition bd = new RootBeanDefinition(CustomSetConstructorInjectionBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", bd);
	RootBeanDefinition tbs = new RootBeanDefinition(CustomCollectionFactoryMethods.class);
	tbs.setUniqueFactoryMethodName("testBeanSet");
	bf.registerBeanDefinition("myTestBeanSet", tbs);

	CustomSetConstructorInjectionBean bean = (CustomSetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
	bean = (CustomSetConstructorInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("myTestBeanSet"), bean.getTestBeanSet());
}