日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring集成Mybatis错误Result Maps collection already contains value for XXX

發(fā)布時間:2023/12/4 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring集成Mybatis错误Result Maps collection already contains value for XXX 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Spring在集成Mybatis出現(xiàn)如下錯誤:

SpringResult Maps collection already contains value for com.guowei.maven.framework.dao.UserMapper.resultUser

at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:468)

at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:343)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutow

ireCapableBeanFactory.java:1637)

其中Spring的配置文件applicationContext.xml如下:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:c="http://www.springframework.org/schema/c"xmlns:cache="http://www.springframework.org/schema/cache"xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee"xmlns:lang="http://www.springframework.org/schema/lang"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"xmlns:p="http://www.springframework.org/schema/p"xmlns:task="http://www.springframework.org/schema/task"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsdhttp://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsdhttp://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.2.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsdhttp://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"><span style="color:#ff0000;"> <!-- 掃描 mappers 自動配置 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.guowei.maven.framework.dao" /> </bean> </span><bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"><property name="locations"><list><value>classpath:mysqldb.properties</value></list></property></bean><bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="ignoreResourceNotFound" value="false" /><property name="properties" ref="configProperties" /></bean><bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"><property name="driverClassName" value="${driver}" /><property name="url" value="${url}" /><property name="username" value="${username}" /><property name="password" value="${password}" /></bean><span style="color:#ff0000;"><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--dataSource屬性指定要用到的連接池--><property name="dataSource" ref="dataSource" /><!--configLocation屬性指定mybatis的核心配置文件--><property name="configLocation" value="mybatisconf.xml" /><!--mapperLocations屬性指定mybatis的映射文件--><property name="mapperLocations" value="classpath*:com/guowei/maven/framework/**/*.xml" /></bean></span></beans>
Mybatis的配置文件mybatisconf.xml內(nèi)容如下:

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><!-- 引用db.properties配置文件 --><properties resource="mysqldb.properties"/><typeAliases><typeAlias alias="User" type="com.guowei.maven.framework.model.User" /><typeAlias alias="Order" type="com.guowei.maven.framework.model.Order" /></typeAliases><span style="color:#ff0000;"><mappers><mapper resource="com/guowei/maven/framework/mapping/UserMapper.xml"/></mappers></span></configuration>


錯誤的原因如下:

因為Spring的配置文件里的MapperScannerConfigurer(或sqlSessionFactoryd的mapperLocation)和mybatis的配置文件都定義了mapper.xml,因此就會出現(xiàn) java.lang.IllegalArgumentException: Result Maps collection already contains value for XXX這個錯誤。


解決方案:

刪除mybatis配置文件里關(guān)于mapper.xml配置的<mappers></mappers>節(jié)點。


參考文獻:

1、http://www.blogjava.net/crazycy/archive/2014/07/07/415523.html

2、http://www.programering.com/a/MDN0QDNwATU.html

3、http://blog.csdn.net/zht666/article/details/38706083

4、http://mybatis.github.io/spring/factorybean.html



總結(jié)

以上是生活随笔為你收集整理的Spring集成Mybatis错误Result Maps collection already contains value for XXX的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。