当前位置: 首页>>代码示例>>Java>>正文


Java RootBeanDefinition.setPropertyValues方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.RootBeanDefinition.setPropertyValues方法的典型用法代码示例。如果您正苦于以下问题:Java RootBeanDefinition.setPropertyValues方法的具体用法?Java RootBeanDefinition.setPropertyValues怎么用?Java RootBeanDefinition.setPropertyValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.support.RootBeanDefinition的用法示例。


在下文中一共展示了RootBeanDefinition.setPropertyValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomEditorConfigurerWithEditorAsClass

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testCustomEditorConfigurerWithEditorAsClass() throws ParseException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	CustomEditorConfigurer cec = new CustomEditorConfigurer();
	Map<Class<?>, Class<? extends PropertyEditor>> editors = new HashMap<Class<?>, Class<? extends PropertyEditor>>();
	editors.put(Date.class, MyDateEditor.class);
	cec.setCustomEditors(editors);
	cec.postProcessBeanFactory(bf);

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("date", "2.12.1975");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	bf.registerBeanDefinition("tb", bd);

	TestBean tb = (TestBean) bf.getBean("tb");
	DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
	assertEquals(df.parse("2.12.1975"), tb.getDate());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CustomEditorConfigurerTests.java

示例2: testCustomEditorConfigurerWithRequiredTypeArray

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testCustomEditorConfigurerWithRequiredTypeArray() throws ParseException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	CustomEditorConfigurer cec = new CustomEditorConfigurer();
	Map<Class<?>, Class<? extends PropertyEditor>> editors = new HashMap<Class<?>, Class<? extends PropertyEditor>>();
	editors.put(String[].class, MyTestEditor.class);
	cec.setCustomEditors(editors);
	cec.postProcessBeanFactory(bf);

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("stringArray", "xxx");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	bf.registerBeanDefinition("tb", bd);

	TestBean tb = (TestBean) bf.getBean("tb");
	assertTrue(tb.getStringArray() != null && tb.getStringArray().length == 1);
	assertEquals("test", tb.getStringArray()[0]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CustomEditorConfigurerTests.java

示例3: testPossibleMatches

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testPossibleMatches() {
	try {
		DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
		MutablePropertyValues pvs = new MutablePropertyValues();
		pvs.add("ag", "foobar");
		RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
		bd.setPropertyValues(pvs);
		lbf.registerBeanDefinition("tb", bd);
		lbf.getBean("tb");
		fail("Should throw exception on invalid property");
	}
	catch (BeanCreationException ex) {
		assertTrue(ex.getCause() instanceof NotWritablePropertyException);
		NotWritablePropertyException cause = (NotWritablePropertyException) ex.getCause();
		// expected
		assertEquals(1, cause.getPossibleMatches().length);
		assertEquals("age", cause.getPossibleMatches()[0]);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:DefaultListableBeanFactoryTests.java

示例4: testCustomEditor

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testCustomEditor() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
		@Override
		public void registerCustomEditors(PropertyEditorRegistry registry) {
			NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
			registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1,1");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("testBean", bd);
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:DefaultListableBeanFactoryTests.java

示例5: testCustomConverter

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testCustomConverter() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	GenericConversionService conversionService = new DefaultConversionService();
	conversionService.addConverter(new Converter<String, Float>() {
		@Override
		public Float convert(String source) {
			try {
				NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
				return nf.parse(source).floatValue();
			}
			catch (ParseException ex) {
				throw new IllegalArgumentException(ex);
			}
		}
	});
	lbf.setConversionService(conversionService);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1,1");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("testBean", bd);
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:DefaultListableBeanFactoryTests.java

示例6: testCustomEditorWithBeanReference

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testCustomEditorWithBeanReference() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
		@Override
		public void registerCustomEditors(PropertyEditorRegistry registry) {
			NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
			registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("testBean", bd);
	lbf.registerSingleton("myFloat", "1,1");
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:DefaultListableBeanFactoryTests.java

示例7: 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

示例8: testExpressionInStringArray

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testExpressionInStringArray() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
	when(beanExpressionResolver.evaluate(eq("#{foo}"), Matchers.any(BeanExpressionContext.class)))
			.thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
	bf.setBeanExpressionResolver(beanExpressionResolver);

	RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("locations", new String[]{"#{foo}"});
	rbd.setPropertyValues(pvs);
	bf.registerBeanDefinition("myProperties", rbd);
	Properties properties = (Properties) bf.getBean("myProperties");
	assertEquals("bar", properties.getProperty("foo"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DefaultListableBeanFactoryTests.java

示例9: testAutowireWithSatisfiedJavaBeanDependency

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testAutowireWithSatisfiedJavaBeanDependency() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", "Rod");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("rod", bd);
	assertEquals(1, lbf.getBeanDefinitionCount());
	// Depends on age, name and spouse (TestBean)
	Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
	assertEquals(1, lbf.getBeanDefinitionCount());
	DependenciesBean kerry = (DependenciesBean) registered;
	TestBean rod = (TestBean) lbf.getBean("rod");
	assertSame(rod, kerry.getSpouse());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DefaultListableBeanFactoryTests.java

示例10: testAutowireWithUnsatisfiedConstructorDependency

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testAutowireWithUnsatisfiedConstructorDependency() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.addPropertyValue(new PropertyValue("name", "Rod"));
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("rod", bd);
	assertEquals(1, lbf.getBeanDefinitionCount());
	try {
		lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
		fail("Should have unsatisfied constructor dependency on SideEffectBean");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:DefaultListableBeanFactoryTests.java

示例11: testExtensiveCircularReference

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testExtensiveCircularReference() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	for (int i = 0; i < 1000; i++) {
		MutablePropertyValues pvs = new MutablePropertyValues();
		pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0))));
		RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
		bd.setPropertyValues(pvs);
		lbf.registerBeanDefinition("bean" + i, bd);
	}
	lbf.preInstantiateSingletons();
	for (int i = 0; i < 1000; i++) {
		TestBean bean = (TestBean) lbf.getBean("bean" + i);
		TestBean otherBean = (TestBean) lbf.getBean("bean" + (i < 99 ? i + 1 : 0));
		assertTrue(bean.getSpouse() == otherBean);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:DefaultListableBeanFactoryTests.java

示例12: postProcessEmbeddedServletContainerFactory

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void postProcessEmbeddedServletContainerFactory() throws Exception {
	RootBeanDefinition bd = new RootBeanDefinition(
			MockEmbeddedServletContainerFactory.class);
	MutablePropertyValues pv = new MutablePropertyValues();
	pv.add("port", "${port}");
	bd.setPropertyValues(pv);
	this.context.registerBeanDefinition("embeddedServletContainerFactory", bd);

	PropertySourcesPlaceholderConfigurer propertySupport = new PropertySourcesPlaceholderConfigurer();
	Properties properties = new Properties();
	properties.put("port", 8080);
	propertySupport.setProperties(properties);
	this.context.registerBeanDefinition("propertySupport",
			beanDefinition(propertySupport));

	this.context.refresh();
	assertThat(getEmbeddedServletContainerFactory().getContainer().getPort())
			.isEqualTo(8080);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:EmbeddedWebApplicationContextTests.java

示例13: testAutowireWithParent

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testAutowireWithParent() throws Exception {
	DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", "kerry");
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("spouse", bd);
	xbf.setParentBeanFactory(lbf);
	doTestAutowire(xbf);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:XmlBeanFactoryTests.java

示例14: parse

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	RootBeanDefinition definition = new RootBeanDefinition();
	definition.setBeanClass(TestBean.class);

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("name", element.getAttribute("name"));
	mpvs.add("age", element.getAttribute("age"));
	definition.setPropertyValues(mpvs);

	parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), definition);

	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:CustomNamespaceHandlerTests.java

示例15: testSelfReference

import org.springframework.beans.factory.support.RootBeanDefinition; //导入方法依赖的package包/类
@Test
public void testSelfReference() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("spouse", new RuntimeBeanReference("self"));
	RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
	bd.setPropertyValues(pvs);
	lbf.registerBeanDefinition("self", bd);
	TestBean self = (TestBean) lbf.getBean("self");
	assertEquals(self, self.getSpouse());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:DefaultListableBeanFactoryTests.java


注:本文中的org.springframework.beans.factory.support.RootBeanDefinition.setPropertyValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。