java.lang.IllegalArgumentException: Mapped Statements collection already contains value for xxx.xxx

初次配置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"/>

解决办法:去除其中一个引入即可

阅读更多

java.lang.IllegalArgumentException: Mapped Statements collection does not conta

11-30

[code=text]严重: Exception occurred during processing request: rn### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for queryAllUserrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for queryAllUserrnorg.apache.ibatis.exceptions.PersistenceException: rn### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for queryAllUserrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for queryAllUserrn at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:94)rn at com.dao.IDao.queryAll(IDao.java:23)rn at com.action.HomeAction.login(HomeAction.java:21)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)rn at java.lang.Thread.run(Unknown Source)rnCaused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for queryAllUserrn at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:791)rn at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:631)rn at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:624)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:103)rn ... 73 morernrn[/code]rnrnentity.xmlrn[code=text]rn rn rn rn rn rn rn select * from usersrn [/code]rnrndaornrn[code=text]public List queryAll()rn //SqlSession sqlSession = GetSqlMap.getSqlSessionFactory().openSession();rn SqlSession sqlSession = sqlSessionFactory.openSession();rn List list = new ArrayList();rn list = sqlSession.selectList("queryAllUser");rn sqlSession.close();rn [/code]

Mapped Statements collection does not contain value for org.mybatis.spring.sampl

04-14

错误信息rn四月 14, 2016 4:06:44 下午 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet [SpringMVC] in context with path [/testdemo] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: rn### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.mybatis.spring.sample.mapper.UserMapper.selectByPrimaryKeyrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.mybatis.spring.sample.mapper.UserMapper.selectByPrimaryKey] with root causernjava.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.mybatis.spring.sample.mapper.UserMapper.selectByPrimaryKeyrn at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:797)rn at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:631)rn at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:624)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)rn at com.sun.proxy.$Proxy12.selectOne(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)rn at com.cn.hnust.dao.UserDaoSupport.findForObject(UserDaoSupport.java:28)rn at com.cn.hnust.service.impl.UserServiceImpl.getUserById(UserServiceImpl.java:20)rn at com.cn.hnust.controller.UserController.toIndex(UserController.java:24)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn[i]mybatis-config.xml:[/i][b][/b]rnrnrnrnrn rn rn rn rn rn rnrn rn rn rn rnrnrnmybatis-spring.xmlrnrnrn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn[i]spring-mvc.xml[/i][b][/b]rnrnrn rn rn rn rn rn rn rn text/html;charset=UTF-8rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnrn[i]UserServiceImpl.java[/i][b][/b]rnpackage com.cn.hnust.service.impl;rnrnimport java.util.List;rnrnimport javax.annotation.Resource;rnrnimport org.springframework.stereotype.Service;rnrnimport com.cn.hnust.dao.UserDaoSupport;rnimport com.cn.hnust.pojo.User;rnimport com.cn.hnust.service.UserService;rnrn@Service("userService")rnpublic class UserServiceImpl implements UserService rn @Resource(name = "userDaoSupport")rn private UserDaoSupport userDaoSupport;rnrn @SuppressWarnings("unchecked")rn public List getUserById(int userId) throws Exception rn return (List) userDaoSupport.findForObject("org.mybatis.spring.sample.mapper.UserMapper.selectByPrimaryKey", userId);rn rn

没有更多推荐了,返回首页