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


Java RootBeanDefinition.setAutowireMode方法代碼示例

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


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

示例1: byTypeAutowireWithPrimaryInParentFactory

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void byTypeAutowireWithPrimaryInParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props1", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AutowireWithExclusionTests.java

示例2: byTypeAutowireWithPrimaryOverridingParentFactory

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AutowireWithExclusionTests.java

示例3: byTypeAutowireWithPrimaryInParentAndChild

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.getBeanDefinition("props1").setPrimary(true);
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
	propsDef.getPropertyValues().add("properties", "name=props3");
	propsDef.setPrimary(true);
	child.registerBeanDefinition("props3", propsDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props3", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:AutowireWithExclusionTests.java

示例4: testRegisterExistingSingletonWithAutowire

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testRegisterExistingSingletonWithAutowire() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", "Tony");
	pvs.add("age", "48");
	RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class);
	bd.setPropertyValues(pvs);
	bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
	bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	lbf.registerBeanDefinition("test", bd);
	Object singletonObject = new TestBean();
	lbf.registerSingleton("singletonObject", singletonObject);

	assertTrue(lbf.containsBean("singletonObject"));
	assertTrue(lbf.isSingleton("singletonObject"));
	assertEquals(TestBean.class, lbf.getType("singletonObject"));
	assertEquals(0, lbf.getAliases("singletonObject").length);
	DependenciesBean test = (DependenciesBean) lbf.getBean("test");
	assertEquals(singletonObject, lbf.getBean("singletonObject"));
	assertEquals(singletonObject, test.getSpouse());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:DefaultListableBeanFactoryTests.java

示例5: testDoubleArrayConstructorWithAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testDoubleArrayConstructorWithAutowiring() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerSingleton("integer1", new Integer(4));
	bf.registerSingleton("integer2", new Integer(5));
	bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
	bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));

	RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	bf.registerBeanDefinition("arrayBean", rbd);
	ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");

	assertEquals(new Integer(4), ab.getIntegerArray()[0]);
	assertEquals(new Integer(5), ab.getIntegerArray()[1]);
	assertEquals(new UrlResource("http://localhost:8080"), ab.getResourceArray()[0]);
	assertEquals(new UrlResource("http://localhost:9090"), ab.getResourceArray()[1]);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:DefaultListableBeanFactoryTests.java

示例6: testConfigureBeanWithAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testConfigureBeanWithAutowiring() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	lbf.registerBeanDefinition("spouse", bd);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("age", "99");
	RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
	tbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_NAME);
	lbf.registerBeanDefinition("test", tbd);
	TestBean tb = new TestBean();
	lbf.configureBean(tb, "test");
	assertSame(lbf, tb.getBeanFactory());
	TestBean spouse = (TestBean) lbf.getBean("spouse");
	assertEquals(spouse, tb.getSpouse());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:DefaultListableBeanFactoryTests.java

示例7: byTypeAutowireWithExclusionInParentFactory

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void byTypeAutowireWithExclusionInParentFactory() throws Exception {
	CountingFactory.reset();
	DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
	parent.preInstantiateSingletons();
	DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
	RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
	robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
	child.registerBeanDefinition("rob2", robDef);
	TestBean rob = (TestBean) child.getBean("rob2");
	assertEquals("props1", rob.getSomeProperties().getProperty("name"));
	assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:AutowireWithExclusionTests.java

示例8: testArrayPropertyWithAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testArrayPropertyWithAutowiring() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
	bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));

	RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	bf.registerBeanDefinition("arrayBean", rbd);
	ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");

	assertEquals(new UrlResource("http://localhost:8080"), ab.getResourceArray()[0]);
	assertEquals(new UrlResource("http://localhost:9090"), ab.getResourceArray()[1]);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:DefaultListableBeanFactoryTests.java

示例9: testArrayPropertyWithOptionalAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testArrayPropertyWithOptionalAutowiring() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();

	RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
	bf.registerBeanDefinition("arrayBean", rbd);
	ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");

	assertNull(ab.getResourceArray());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:DefaultListableBeanFactoryTests.java

示例10: testArrayConstructorWithAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testArrayConstructorWithAutowiring() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerSingleton("integer1", new Integer(4));
	bf.registerSingleton("integer2", new Integer(5));

	RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	bf.registerBeanDefinition("arrayBean", rbd);
	ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");

	assertEquals(new Integer(4), ab.getIntegerArray()[0]);
	assertEquals(new Integer(5), ab.getIntegerArray()[1]);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:DefaultListableBeanFactoryTests.java

示例11: testArrayConstructorWithOptionalAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testArrayConstructorWithOptionalAutowiring() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();

	RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	bf.registerBeanDefinition("arrayBean", rbd);
	ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");

	assertNull(ab.getIntegerArray());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:DefaultListableBeanFactoryTests.java

示例12: testDoubleArrayConstructorWithOptionalAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testDoubleArrayConstructorWithOptionalAutowiring() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
	bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));

	RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	bf.registerBeanDefinition("arrayBean", rbd);
	ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");

	assertNull(ab.getIntegerArray());
	assertNull(ab.getResourceArray());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:DefaultListableBeanFactoryTests.java

示例13: testCircularReferenceThroughAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testCircularReferenceThroughAutowiring() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyBean.class);
	bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	lbf.registerBeanDefinition("test", bd);
	try {
		lbf.preInstantiateSingletons();
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException expected) {
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:DefaultListableBeanFactoryTests.java

示例14: testCircularReferenceThroughFactoryBeanAutowiring

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testCircularReferenceThroughFactoryBeanAutowiring() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
	bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	lbf.registerBeanDefinition("test", bd);
	try {
		lbf.preInstantiateSingletons();
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException expected) {
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:DefaultListableBeanFactoryTests.java

示例15: testCircularReferenceThroughFactoryBeanTypeCheck

import org.springframework.beans.factory.support.RootBeanDefinition; //導入方法依賴的package包/類
@Test
public void testCircularReferenceThroughFactoryBeanTypeCheck() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
	bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	lbf.registerBeanDefinition("test", bd);
	try {
		lbf.getBeansOfType(String.class);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException expected) {
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:DefaultListableBeanFactoryTests.java


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