今天测试mybatis接口时遇到一个小问题,花了好长时间
Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\idea\SSM-CRUD\src\main\resources\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.crazy.dao.EmployeeMapper.BaseResultMap
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\idea\SSM-CRUD\src\main\resources\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.codegen.dao.EmployeeMapper.BaseResultMap
最后找到报错的 mapper.xml 文件 搜索BaseResultMap 这个关键字,果然出现了两次 BaseResultMap。
这个问题的产生原因是:使用 mybatis 逆向工程多次生成 mapper 时,未将之前生成的 mapper.xml 删除,导致其在原有的xml里面追加内容。最终导致 BaseResultMap 重复。删除已生成的 mapper.xml 文件, 重新生成即可。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/187600.html原文链接:https://javaforall.net