Java Code Examples for org.springframework.beans.factory.support.DefaultListableBeanFactory#setTypeConverter()

The following examples show how to use org.springframework.beans.factory.support.DefaultListableBeanFactory#setTypeConverter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testCustomTypeConverter() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
	lbf.setTypeConverter(new CustomTypeConverter(nf));
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1,1");
	ConstructorArgumentValues cav = new ConstructorArgumentValues();
	cav.addIndexedArgumentValue(0, "myName");
	cav.addIndexedArgumentValue(1, "myAge");
	lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertEquals("myName", testBean.getName());
	assertEquals(5, testBean.getAge());
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
Example 2
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testCustomTypeConverterWithBeanReference() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
	lbf.setTypeConverter(new CustomTypeConverter(nf));
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
	ConstructorArgumentValues cav = new ConstructorArgumentValues();
	cav.addIndexedArgumentValue(0, "myName");
	cav.addIndexedArgumentValue(1, "myAge");
	lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
	lbf.registerSingleton("myFloat", "1,1");
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertEquals("myName", testBean.getName());
	assertEquals(5, testBean.getAge());
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
Example 3
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testCustomTypeConverter() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
	lbf.setTypeConverter(new CustomTypeConverter(nf));
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1,1");
	ConstructorArgumentValues cav = new ConstructorArgumentValues();
	cav.addIndexedArgumentValue(0, "myName");
	cav.addIndexedArgumentValue(1, "myAge");
	lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertEquals("myName", testBean.getName());
	assertEquals(5, testBean.getAge());
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
Example 4
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testCustomTypeConverterWithBeanReference() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
	lbf.setTypeConverter(new CustomTypeConverter(nf));
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
	ConstructorArgumentValues cav = new ConstructorArgumentValues();
	cav.addIndexedArgumentValue(0, "myName");
	cav.addIndexedArgumentValue(1, "myAge");
	lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
	lbf.registerSingleton("myFloat", "1,1");
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertEquals("myName", testBean.getName());
	assertEquals(5, testBean.getAge());
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
Example 5
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomTypeConverter() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
	lbf.setTypeConverter(new CustomTypeConverter(nf));
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", "1,1");
	ConstructorArgumentValues cav = new ConstructorArgumentValues();
	cav.addIndexedArgumentValue(0, "myName");
	cav.addIndexedArgumentValue(1, "myAge");
	lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertEquals("myName", testBean.getName());
	assertEquals(5, testBean.getAge());
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
 
Example 6
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomTypeConverterWithBeanReference() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
	lbf.setTypeConverter(new CustomTypeConverter(nf));
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
	ConstructorArgumentValues cav = new ConstructorArgumentValues();
	cav.addIndexedArgumentValue(0, "myName");
	cav.addIndexedArgumentValue(1, "myAge");
	lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
	lbf.registerSingleton("myFloat", "1,1");
	TestBean testBean = (TestBean) lbf.getBean("testBean");
	assertEquals("myName", testBean.getName());
	assertEquals(5, testBean.getAge());
	assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}