报错,Result Maps collection already contains value for

环境: spring boot + mybatis
报错: Result Maps collection already contains value for xxx

<?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>
    <mappers>
        <mapper resource="mapper/HelloMapper.xml"/>
    </mappers>
</configuration>

将mapper.xml删除,报错找不到mapper,证明这个mapper.xml是生效的。将mapper.xml的内容全部删除,写了一个最简单的<select>,发现还是报错,这说明跟mapper.xml本身是没有关系的。

折腾了2个小时,终于搞明白了是怎么回事。
原来在spring boot的application.properties中,配置了

mybatis.config-location=classpath:mybatis-config.xml
mybatis.mapper-locations=classpath*:mapper/*.xml

这样相当于mapper的配置被配置了两遍,把mybatis-config.xml中的mappers部分删除,单测终于跑通。
spring boot的这个配置省的每次都要把xml写到mybatis-config.xml里边了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。