在使用SimpleJdbcDaoSupport作为基类创建Dao时候出现的奇怪的BUG
2015-10-23 22:50
549 查看
今天在练习使用SimpleJdbcDaoSupport时候,出现了一个莫名奇妙的BUG,现记录如下:
XML中配置如下:
其中JdbcTestDaoImpl类继承了SimpleJdbcDaoSupport:
但是在使用时出现错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcTestDaoImpl' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.jdbc.core.simple.SimpleJdbcTemplate' to required type 'org.springframework.jdbc.core.JdbcTemplate' for property 'jdbcTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.jdbc.core.simple.SimpleJdbcTemplate] to required type
说是从org.springframework.jdbc.core.simple.SimpleJdbcTemplate转换到org.springframework.jdbc.core.JdbcTemplate类的异常,但是查看SimpleJdbcDaoSupport 的源代码可见其属性simpleJdbcTemplate的类正是org.springframework.jdbc.core.simple.SimpleJdbcTemplate,就是上面所说的需要转换之前的类所以并不需要类型转换。于是我在XML中将要注入的Bean
jdbcTemplate的类型改为转换的目标类org.springframework.jdbc.core.JdbcTemplate,顺利通过。
但是问题还是没有解决,为什么要求的类与原类一致却仍然说要进行转换呢?目标类型为什么与类内自己定义的类型不一致呢?
XML中配置如下:
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate"> <constructor-arg ref="dataSource"/> </bean> <!-- <bean id="testDaoImpl" class="com.zdz.dao.TestDaoImpl"> <property name="jdbcTemplate" ref="jdbcTemplate"></property> </bean> --> <bean id="jdbcTestDaoImpl" class="com.zdz.dao.JdbcTestDaoImpl"> <property name="jdbcTemplate" ref="jdbcTemplate"></property> </bean>
其中JdbcTestDaoImpl类继承了SimpleJdbcDaoSupport:
public class JdbcTestDaoImpl extends SimpleJdbcDaoSupport
但是在使用时出现错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcTestDaoImpl' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.jdbc.core.simple.SimpleJdbcTemplate' to required type 'org.springframework.jdbc.core.JdbcTemplate' for property 'jdbcTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.jdbc.core.simple.SimpleJdbcTemplate] to required type
说是从org.springframework.jdbc.core.simple.SimpleJdbcTemplate转换到org.springframework.jdbc.core.JdbcTemplate类的异常,但是查看SimpleJdbcDaoSupport 的源代码可见其属性simpleJdbcTemplate的类正是org.springframework.jdbc.core.simple.SimpleJdbcTemplate,就是上面所说的需要转换之前的类所以并不需要类型转换。于是我在XML中将要注入的Bean
jdbcTemplate的类型改为转换的目标类org.springframework.jdbc.core.JdbcTemplate,顺利通过。
但是问题还是没有解决,为什么要求的类与原类一致却仍然说要进行转换呢?目标类型为什么与类内自己定义的类型不一致呢?
相关文章推荐
- SourceProvider.getJniDirectories
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Trac 中文语言安装
- 软件 bug 的生命周期
- Firefox2中输入框丢失光标bug的解决方法
- for命令的一些bug分析
- 修正IE下使用CSS属性overflow的bug
- 解决IE6 3像素Bug的css写法
- JS注释所产生的bug 即使注释也会执行
- IE本地存储userdata的一个bug说明
- IE在DOM操作有表单控件时的bug
- ie 处理 gif动画 的onload 事件的一个 bug
- 模拟Spring的简单实现
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- struts2 spring整合fieldError问题
- IIS6 安全性存在超级BUG,快来看
- Android生存指南之:解Bug策略与思路问题的详解