版本: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;
}
}
配置文件:
1
2.2
测试代码:
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"
Spring基本类型注入
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- DreamZhong 2011-09-15 09:29关注
你的doubleProperty是int类型,转换当然要出错了。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 java业务性能问题求解(sql,业务设计相关)
- ¥15 52810 尾椎c三个a 写蓝牙地址
- ¥15 elmos524.33 eeprom的读写问题
- ¥15 使用Java milo连接Kepserver服务端报错?
- ¥15 用ADS设计一款的射频功率放大器
- ¥15 怎么求交点连线的理论解?
- ¥20 软件开发方法学习来了
- ¥15 微信小程序商城如何实现多商户收款 平台分润抽成
- ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B
- ¥15 cocos的js代码调用wx.createUseInfoButton问题!