问题描述
版本:spring-framework-2.5.6类:public class ExampleBean {private int integerProperty;private int doubleProperty;public int getIntegerProperty() {return integerProperty;}public void setIntegerProperty(int integerProperty) {this.integerProperty = integerProperty;}public int getDoubleProperty() {return doubleProperty;}public void setDoubleProperty(int doubleProperty) {this.doubleProperty = doubleProperty;}}配置文件:<bean id="exampleBean" class="com.xxx.impl.ExampleBean"> <property name="integerProperty"> <value>1</value> </property> <property name="doubleProperty"> <value>2.2</value> </property> </bean>测试代码:FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext(new String[]{"src/beans.xml"});BeanFactory factory = (BeanFactory) appContext;ExampleBean b1 = (ExampleBean) factory.getBean("exampleBean");System.out.println(b1.getIntegerProperty()+"——"+b1.getDoubleProperty());出错:Caused by: java.lang.NumberFormatException: For input string: "2.2"
解决方案
你的doubleProperty是int类型,转换当然要出错了。