当前位置: 首页>>代码示例>>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;未经允许,请勿转载。