IllegalArgumentException: Mapped Statements collection already contains value for ***Mapper.insert!s

目录

一:异常/错误

二:分析/排查

三:解决方法


一:异常/错误

IllegalArgumentException: Mapped Statements collection already contains value for ***Mapper.insert!selectKey

[artifact:mvn] 2016-05-07 11:39:21,708 [ERROR] org.mybatis.spring.mapper.MapperFactoryBean - Error while adding the mapper 'interface com.sample.mappers.UserMapper' to configuration.
[artifact:mvn] java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.sample.mappers.UserMapper.getAllUsers
[artifact:mvn]  at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:802)
[artifact:mvn]  at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:774)
[artifact:mvn]  at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:598)
[artifact:mvn]  at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:300)
[artifact:mvn]  at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:313)
[artifact:mvn]  at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:128)
[artifact:mvn]  at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:72)
[artifact:mvn]  at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:671)
[artifact:mvn]  at org.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:81)
[artifact:mvn]  at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)

二:分析/排查

出现这个错误的意思是:SQL标签中有 id 重复的标签,或者说有相同的方法名称

 

三:解决方法

解决方案:为不同的映射器语句使用不同的方法名称,即使方法签名不同。

  1. 如果是自己写的mapper,建议手动排查是否有重复id的sql,例如: https://blog.csdn.net/kingscoming/article/details/78897459

  2. 如果是通过mybatis逆向工程生成的代码,那肯定是不会有重复的id,那么问题很可能出现在同时有xml配置文件的mapper和java注解的mapper,删除一个就好了

 

ref:https://stackoverflow.com/questions/37085803/mybatis-mapped-statements-collection-already-contains-value-for

你可能感兴趣的:(数据库)