環(huán)境: spring boot + mybatis
報(bào)錯(cuò): 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刪除,報(bào)錯(cuò)找不到mapper,證明這個(gè)mapper.xml是生效的。將mapper.xml的內(nèi)容全部刪除,寫了一個(gè)最簡(jiǎn)單的<select>,發(fā)現(xiàn)還是報(bào)錯(cuò),這說明跟mapper.xml本身是沒有關(guān)系的。
折騰了2個(gè)小時(shí),終于搞明白了是怎么回事。
原來在spring boot的application.properties中,配置了
mybatis.config-location=classpath:mybatis-config.xml
mybatis.mapper-locations=classpath*:mapper/*.xml
這樣相當(dāng)于mapper的配置被配置了兩遍,把mybatis-config.xml中的mappers部分刪除,單測(cè)終于跑通。
spring boot的這個(gè)配置省的每次都要把xml寫到mybatis-config.xml里邊了