本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}
示例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]);
}
示例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());
}
示例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());
}
示例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]);
}
示例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());
}
示例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]);
}
示例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());
}
示例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());
}
示例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) {
}
}
示例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) {
}
}
示例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) {
}
}