當前位置: 首頁>>代碼示例>>Java>>正文


Java RootBeanDefinition.setAutowireCandidate方法代碼示例

本文整理匯總了Java中org.springframework.beans.factory.support.RootBeanDefinition.setAutowireCandidate方法的典型用法代碼示例。如果您正苦於以下問題:Java RootBeanDefinition.setAutowireCandidate方法的具體用法?Java RootBeanDefinition.setAutowireCandidate怎麽用?Java RootBeanDefinition.setAutowireCandidate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.factory.support.RootBeanDefinition的用法示例。


在下文中一共展示了RootBeanDefinition.setAutowireCandidate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(MapMethodInjectionBean.class));
	bf.registerBeanDefinition("testBean1", new RootBeanDefinition(TestBean.class));
	RootBeanDefinition rbd2 = new RootBeanDefinition(TestBean.class);
	rbd2.setAutowireCandidate(false);
	bf.registerBeanDefinition("testBean2", rbd2);

	MapMethodInjectionBean bean = (MapMethodInjectionBean) bf.getBean("annotatedBean");
	TestBean tb = (TestBean) bf.getBean("testBean1");
	assertEquals(1, bean.getTestBeanMap().size());
	assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
	assertTrue(bean.getTestBeanMap().values().contains(tb));
	assertSame(tb, bean.getTestBean());
	bf.destroySingletons();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:AutowiredAnnotationBeanPostProcessorTests.java

示例2: testGetBeanByTypeFiltersOutNonAutowireCandidates

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testGetBeanByTypeFiltersOutNonAutowireCandidates() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
	RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
	RootBeanDefinition na1 = new RootBeanDefinition(TestBean.class);
	na1.setAutowireCandidate(false);

	lbf.registerBeanDefinition("bd1", bd1);
	lbf.registerBeanDefinition("na1", na1);
	TestBean actual = lbf.getBean(TestBean.class); // na1 was filtered
	assertSame(lbf.getBean("bd1", TestBean.class), actual);

	lbf.registerBeanDefinition("bd2", bd2);
	try {
		lbf.getBean(TestBean.class);
		fail("Should have thrown NoSuchBeanDefinitionException");
	}
	catch (NoSuchBeanDefinitionException ex) {
		// expected
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:DefaultListableBeanFactoryTests.java

示例3: testGetBeanByTypeInstanceFiltersOutNonAutowireCandidates

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testGetBeanByTypeInstanceFiltersOutNonAutowireCandidates() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd1 = createConstructorDependencyBeanDefinition(99);
	RootBeanDefinition bd2 = createConstructorDependencyBeanDefinition(43);
	RootBeanDefinition na1 = createConstructorDependencyBeanDefinition(21);
	na1.setAutowireCandidate(false);

	lbf.registerBeanDefinition("bd1", bd1);
	lbf.registerBeanDefinition("na1", na1);
	ConstructorDependency actual = lbf.getBean(ConstructorDependency.class, 42); // na1 was filtered
	assertThat(actual.beanName, equalTo("bd1"));

	lbf.registerBeanDefinition("bd2", bd2);
	try {
		lbf.getBean(TestBean.class, 67);
		fail("Should have thrown NoSuchBeanDefinitionException");
	}
	catch (NoSuchBeanDefinitionException ex) {
		// expected
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:DefaultListableBeanFactoryTests.java

示例4: createScopedProxy

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
/**
 * Generate a scoped proxy for the supplied target bean, registering the target
 * bean with an internal name and setting 'targetBeanName' on the scoped proxy.
 * @param definition the original bean definition
 * @param registry the bean definition registry
 * @param proxyTargetClass whether to create a target class proxy
 * @return the scoped proxy definition
 */
public static BeanDefinitionHolder createScopedProxy(BeanDefinitionHolder definition,
		BeanDefinitionRegistry registry, boolean proxyTargetClass) {

	String originalBeanName = definition.getBeanName();
	BeanDefinition targetDefinition = definition.getBeanDefinition();
	String targetBeanName = getTargetBeanName(originalBeanName);

	// Create a scoped proxy definition for the original bean name,
	// "hiding" the target bean in an internal target definition.
	RootBeanDefinition proxyDefinition = new RootBeanDefinition(ScopedProxyFactoryBean.class);
	proxyDefinition.setDecoratedDefinition(new BeanDefinitionHolder(targetDefinition, targetBeanName));
	proxyDefinition.setOriginatingBeanDefinition(targetDefinition);
	proxyDefinition.setSource(definition.getSource());
	proxyDefinition.setRole(targetDefinition.getRole());

	proxyDefinition.getPropertyValues().add("targetBeanName", targetBeanName);
	if (proxyTargetClass) {
		targetDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
		// ScopedProxyFactoryBean's "proxyTargetClass" default is TRUE, so we don't need to set it explicitly here.
	}
	else {
		proxyDefinition.getPropertyValues().add("proxyTargetClass", Boolean.FALSE);
	}

	// Copy autowire settings from original bean definition.
	proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
	proxyDefinition.setPrimary(targetDefinition.isPrimary());
	if (targetDefinition instanceof AbstractBeanDefinition) {
		proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
	}

	// The target bean should be ignored in favor of the scoped proxy.
	targetDefinition.setAutowireCandidate(false);
	targetDefinition.setPrimary(false);

	// Register the target bean as separate bean in the factory.
	registry.registerBeanDefinition(targetBeanName, targetDefinition);

	// Return the scoped proxy definition as primary bean definition
	// (potentially an inner bean).
	return new BeanDefinitionHolder(proxyDefinition, originalBeanName, definition.getAliases());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:51,代碼來源:ScopedProxyUtils.java


注:本文中的org.springframework.beans.factory.support.RootBeanDefinition.setAutowireCandidate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。