首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

Spring整合MyBatis异常:Mapped Statements collection does not contain value for

2012-08-22 
Spring整合MyBatis错误:Mapped Statements collection does not contain value forMyBatis Mapper使用Spri

Spring整合MyBatis错误:Mapped Statements collection does not contain value for
MyBatis Mapper使用Spring注入:
applicationContext.xml


使用上面方式注入时需要注意下面问题:
- interface = com.itsyc.fmpp.mappers.StudentMapper.class
- mapper file = /com/itsyc/fmpp/mappers/StudentMapper.xml
- mapper namespace = com.itsyc.fmpp.mappers.StudentMapper
这三者必须相同否则会出现下面错误:
Stacktraces
java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.itsyc.fmpp.mappers.StudentMapper.getById

2011-04-22更新:
软件版本:
mybatis: 3.0.4
spring: 3.0.5
mybatis-spring: 1.0.0

更正:mapper file是可以和interface、namespace不同的(注意:interface和namespace必须相同),但这时需要进行配置。
方式一:
1.在MyBatis配置文件中添加mappers:
mybatis-config.xml

2.使用configLocation,在Spring配置文件中添加MyBatis配置文件的引用:
applicationContext.xml

方式二:
使用mapperLocations,MyBatis-Spring会自动地扫描该路径下的所有Mapper文件:
applicationContext.xml


具体请查看mybatis-spring的参考手册: 1 楼 hellostory 2011-09-08   再补充一句:
如果StudentMapper.java里面的方法名称等在StudentMapper.xml找不到,也会出现上次错误!

热点排行