apache.common.dbutils的BeanHandler的“缺陷”?
来源:互联网 发布:裁决网络 编辑:程序博客网 时间:2024/05/21 08:57
先看一下BUG信息:
异常:
16:46:57.472 ERROR - DbUtilsExecutor-find:Cannot create com.keydak.gateguard.database.bean.gategd.GateController: com.keydak.gateguard.database.bean.gategd.GateController Query: SELECT * FROM t_gg_gate_controller WHERE controller_id =
apache.common.dbutils利用BeanHandler<T>对JDBC返回的resultSet进行处理,从而获得bean.
BeanHandler<T>利用泛化所有类型的bean都支持处理,内部源码采用了
(该类的功能网上搜索一下可以会的官方的接口文档)
下面这一段是核心部分
/** * Factory method that returns a new instance of the given Class. This * is called at the start of the bean creation process and may be * overridden to provide custom behavior like returning a cached bean * instance. * @param <T> The type of object to create * @param c The Class to create an object from. * @return A newly created object of the Class. * @throws SQLException if creation failed. */protected <T> T newInstance(Class<T> c) throws SQLException { try { return c.newInstance(); } catch (InstantiationException e) { throw new SQLException( "Cannot create " + c.getName() + ": " + e.getMessage()); } catch (IllegalAccessException e) { throw new SQLException( "Cannot create " + c.getName() + ": " + e.getMessage()); }}
可以看到整个泛化过程都依赖于反射技术,也就是说,Bean必须具备有被反射的条件。
我们看到了这一句
c.newInstance();
利用反射调用了无参构造函数,也就是说Bean必须要有无参构造函数。这里如果Bean没有声明无参构造函数就会创建Bean失败了。
解决问题的方法:
Dbutils要用源码包,单步调试可以发现问题。
优化Dbutils的想法:在异常信息进行详细描述。
0 0
- apache.common.dbutils的BeanHandler的“缺陷”?
- apache common-dbutils 的使用
- common-dbutils的使用
- Common Dbutils组件的使用
- apache--dbutils的使用
- apache的dbUtils的使用
- Apache的DBUtils框架学习
- Apache的DBUtils框架学习
- JDBC:Apache DBUtils的使用
- Apache的DBUtils框架学习
- Apache的DBUtils框架学习
- Apache的DBUtils使用详解
- Apache的DBUtils框架学习
- Apache之DBUtils的使用
- Apache的DBUtils框架学习
- Apache的DBUtils框架学习
- Apache的DBUtils框架学习
- Apache的DbUtils组件学习
- 第十二周-求斐波那契数列的第N项
- 22-Jquery data
- C语言条件编译及编译预处理阶段
- [深度学习论文笔记][Video Classification] Two-Stream Convolutional Networks for Action Recognition in Videos
- golang方法
- apache.common.dbutils的BeanHandler的“缺陷”?
- 将hdfs上的数据传入hbase表中
- 28-基础事件
- centos6.x安装chrominum浏览器(原…
- DBUtils使用详细示例(转)
- DButil善用Handler()来取出自己想…
- unity播放视频问题杂谈
- jquery实现无刷新滚屏加载
- MFC双缓存绘图实现