初次配置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"/>
解决办法:去除其中一个引入即可