xiaosunnihaomang 2011-09-15 09:18
浏览 259
已采纳

Spring基本类型注入

版本: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"

  • 写回答

1条回答 默认 最新

  • DreamZhong 2011-09-15 09:29
    关注

    你的doubleProperty是int类型,转换当然要出错了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接