Spring整合iBatis之一:整合中遇到的错误总结

Spring整合iBatis之一:整合中遇到的异常总结



    刚刚用了两个多小时,把之前写的spring代码和iBatis代码整合到了一块儿,各种包的导入和各种依赖关系比较头疼,要修改不少东西,也出了不少错误。

    先说说整合时候遇到的异常,代码还要再整理整理加加注释什么的,再一段一段慢慢分析,结构大概是这样:

    Spring整合iBatis之一:整合中遇到的错误总结


    


先把异常晒出来,其中好几个异常查了好半天,希望贴出来能造福全人类 哈哈:


1.dataSource(数据源bean)配置错误:

spring没有使用合适的类,

配置dataSource时,class="org.apache.commons.dbcp.BasicDataSource"就行了


2.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool

加commons包

MyEclipse10的安装目录下搜索:commons-pool.jar,commons-logging.jar,commons-dbcp.jar这三个包,找好了导入进去

(其实还少个commons-collections-3.0.jar,后边出这个错了)



3.NoClassDefFoundError: com/ibatis/common/xml/NodeletException

加ibatis-sqlmap包

MyEclipse10的安装目录下搜ibatis-sqlmap-2.jar



4.NoSuchMethodError: com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;

重新导入ibatis.jar,

后来我改用ibatis-2.3.4.726.zip,这个版本就没问题了


5.XML-parse错误:

配置路径没改过来,

原来iBatis里没有model层,对应的vo层改过来以后,每一个配置文件都要改,

疏忽少改了一个,xml里又给不出提示


6.NotWritablePropertyException: Invalid property 'StudentService' of bean class [com.rt.sidemo.service.StudentService]: Bean property 'StudentService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

增加完属性没有配套的setter

spring配置文件applicationContext-common.xml通过反射,把注入了dataSource的iBatis配置实例注入dao,最后将上述实例注入service,都靠setter方法



7.不能使用namespace :

ibatis的SqlMapConfig.xml里加namespace=true,启用命名空间

最后ibatis配置文件SqlMapConfig.xml,只有命名空间的配置 以及 各个model和表对应的xml



8.NoClassDefFoundError: org/apache/commons/collections/CursorableLinkedList:

导入commons-collections.jar

MyEclipse安装目录下搜一个