java.lang.IllegalArgumentException: Mapped Statements collection already contains value for xxx.xxx
阿新 • • 發佈:2018-11-03
初次配置mybatis,執行時出錯,報錯資訊如下
java.lang.IllegalArgumentException: Mapped Statements collection already contains value for xxx.xxx.dao.methodname
後來發現原來是mybatis.xml檔案中對mapper.xml檔案引入了兩次
以下是我的配置:
mybatis.xml配置sqlSessionFactory
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:sqlMapConfig.xml"/> <property name="mapperLocations" value="classpath:sqlmap/*.xml"/> </bean>
sqlMapConfig.xml引入mapper.xml
<mappers> <mapper resource="sqlmap/ResultSqlMap.xml"/> </mappers>
錯誤原因:在sqlMapConfig.xml中已經引入了mapper.xml檔案,在mybatis.xml中又引入了一次
<property name="mapperLocations" value="classpath:sqlmap/*.xml"/>
解決辦法:去除其中一個引入即可