1、错误的一些信息:
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\eclipse\eclipse_new_new\maven\ssm-crud3\target\classes\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\eclipse\eclipse_new_new\maven\ssm-crud3\target\classes\mapper\EmployeeMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[WithDeptResultMap]_association[department]
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:613)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:491)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 41 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\eclipse\eclipse_new_new\maven\ssm-crud3\target\classes\mapper\EmployeeMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[WithDeptResultMap]_association[department]
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:122)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:94)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:611)
... 44 more
Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[WithDeptResultMap]_association[department]
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:947)
2、原因:
根据以上报错信息错误原因是:
在这个文件中EmployeeMapper.xml
里面有很多相同的id值为WithDeptResult的相同的语句
下面的是个列子,反正就是类似的。
<resultMap type="com.feng.crud.bean.Employee" id="WithDeptResultMap">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="gender" jdbcType="CHAR" property="gender" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="d_id" jdbcType="INTEGER" property="dId" />
<association property="department" javaType="com.feng.crud.bean.Department">
<id column="id" property="id"/>
<result column="name" property="name"/>
</association>
</resultMap>
<resultMap type="com.feng.crud.bean.Employee" id="WithDeptResultMap">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="gender" jdbcType="CHAR" property="gender" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="d_id" jdbcType="INTEGER" property="dId" />
<association property="department" javaType="com.feng.crud.bean.Department">
<id column="id" property="id"/>
<result column="name" property="name"/>
</association>
</resultMap>
3、解决办法,根据报错信息,把对应的id值复制好,到对应的EmployeeMapper.xml文件中Ctrl+F 查找刚刚复制的id的值然后把那个语句块删除掉,或者注释掉
4、产生那个错误的原因之一:
我这个是ssm(springmvc+spring+mybatis)框架的简单crud(增删改查),我使用的是mybatis的逆向工程(mybatis generator),在工程的mbg.xml文件写好之后并且写好了那个对应的测试文件,我重复执行了几次这个文件的测试文件,就导致产生了多个相同的id值的相同语句在相同的*Mapper.xml文件中(测试执行下一次之前没有删除之前的)。
5、发现这个错误参考了这个博主