一、报错
Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.SF.springcloud.dao.DeptDao.addDept. please check mapper/DeptMapper.xml and file[D:\Code\SpringCloud\SpringCloud-provider-dept8001\target\classes\mapper\DeptMapper.xml]atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
二、产生原因
查看了网上的教程
- Mapper中存在了重复的id
- parameterType和resultType,参数类型错误
但我确实不是这个问题
后来从重新整体看代码代码发现 在写Dao时候加了@Mapper
注解,在编写mybatis-config.xml
时又加了对应mapper.xml
导致sqlSessionFactory中xml地址配重复了、会报错已经存在( already contains value)
三、解决方式
- Mapper中存在了重复的id
- parameterType和resultType参数类型错误
- sqlSessionFactory中配置了多个xml的地址。xml地址配重复了,将多余的删除掉。
- 同一mapper文件被扫描了多次,导致异常