严重: Exception sending context initialized event to listener instance of class org.springframework.we
b.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFa
ctory' defined in URL [file:/H:/webWorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtp
webapps/mybatisSpringMVC/WEB-INF/classes/config/applicationContext.xml]: Invocation of init method f
ailed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resou
rce: 'file [H:\webWorkSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\mybatisSp
ringMVC\WEB-INF\classes\com\yihaomen\mapper\User.xml]'; nested exception is java.lang.RuntimeExcepti
on: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection alre
ady contains value for com.yihaomen.inter.IUserOperation.resultListUser
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(Abst
ractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
93)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(De
faultListableBeanFactory.java:587)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(A
bstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContex
t.java:472)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLo
ader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.j
ava:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [H:\w
ebWorkSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\mybatisSpringMVC\WEB-INF\
classes\com\yihaomen\mapper\User.xml]'; nested exception is java.lang.RuntimeException: Error parsin
g Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains val
ue for com.yihaomen.inter.IUserOperation.resultListUser
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:412)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:295)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(A
bstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(Abst
ractAutowireCapableBeanFactory.java:1452)
... 21 more
Caused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentExc
eption: Result Maps collection already contains value for com.yihaomen.inter.IUserOperation.resultLi
stUser
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:113)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:88)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:410)
... 24 more
Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com
.yihaomen.inter.IUserOperation.resultListUser
将spring和mybatis集成时,启动eclipse控制台报错 Result Maps collection alre ady contains value for XXXX
自己的配置如下
User.xml
<mapper namespace="com.yihaomen.inter.IUserOperation">
<select id="selectUserByID" parameterType="int" resultType="User">
select * from user where id = #{id}
</select>
<resultMap type="User" id="resultListUser">
<id column="id" property="id" />
<result column="userName" property="userName" />
<result column="userAge" property="userAge" />
<result column="userAddress" property="userAddress" />
</resultMap>
<select id="selectUsers" parameterType="string" resultMap="resultListUser">
select * from user where userName like #{userName}
</select>
Configuration.xml
<configuration>
<typeAliases>
<typeAlias alias="User" type="com.yihaomen.model.User"/>
<typeAlias alias="Article" type="com.yihaomen.model.Article"/>
</typeAliases>
<mappers>
<mapper resource="com/yihaomen/mapper/User.xml"/>
</mappers>
</configuration>
解决方法:
将Configuration.xml中的mappers注释掉,原因是user.xml中namespace声明的接口路径和user.xml在同一路径下,不需要再Configuration.xml中显示加载。
参考:
http://www.cnblogs.com/huanmieuroshui/archive/2012/12/18/2822754.html
http://blog.csdn.net/kutejava/article/details/9164353#t5