In the past two days, the project needs to integrate the three major frameworks of spring, struts2, and mybatis, but this error always occurs when it is launched, which has troubled me for a long time. The answers I found online are not what I want. Today I finally know the reason.
The user-mapper.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.bmdc.dj.user.dao.UserDao"> <resultMap type="user" id="userResult"> <id property="user_id" column="USER_ID"/> <result property="login_name" column="LOGIN_NAME"/> <result property="real_name" column="REAL_NAME"/> <result property="password" column="PASSWORD"/> </resultMap> <insert id="add" parameterType="user"> insert into users (user_id, login_name, real_name, password) values(#{user_id}, #{login_name}, #{real_name}, #{password}) </insert> </mapper>Where namespace is the interface path.
Mybatis.xml is as follows:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- Alias--> <typeAliases> <typeAlias type="com.bmdc.dj.user.domain.User" alias="user"/> </typeAliases> <mapper resource="com/bmdc/dj/user/dao/user-mapper.xml" /> </mappers> </configuration>
The other configuration files are correct, so I won't write them. This will cause the error Java.lang.IllegalArgumentException: Result Maps collection already contains value for XXX.
The solution is: delete all contents of the <mappers> tag in Mybatis.xml. Because if the interface between user-mapper.xml and namespace are in the same path, there is no need to configure it in mybaits.xml.
The modified Mybatis.xml is as follows:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- Alias--> <typeAliases> <typeAlias type="com.bmdc.dj.user.domain.User" alias="user"/> </typeAliases> </configuration>
The above is the editor’s introduction to how to solve Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for X. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!