最新消息:关注【太平洋学习网】微信公众号,可以获取全套资料,【全套Java基础27天】【JavaEE就业视频4个月】【Android就业视频4个月】

Mapped Statements collection already contains value for com.voavoice.dao.ArticlesMapper.insert

Javaweb 太平洋学习网 浏览 评论

小编启动javaweb项目的时候,出现了“Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert”等相关错误,说是“sqlSessionFactory”这个bean创建失败,在“ArticlesMapper.xml”文件中有重复的insert方法,如下所示:

Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\web\src\project\english\target\classes\mapper\ArticlesMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert

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

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

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)

... 111 more

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert

at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:782)

at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:754)

at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:578)

at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:288)

at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:307)

at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:127)

at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:71)

at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:651)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.bindMapperForNamespace(XMLMapperBuilder.java:405)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:94)

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

... 114 more

Related cause:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'articlesMapper' defined in file [D:\web\src\project\english\target\classes\com\voavoice\english\dao\ArticlesMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\web\src\project\english\target\classes\mapper\ArticlesMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\web\src\project\english\target\classes\mapper\ArticlesMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\web\src\project\english\target\classes\mapper\ArticlesMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1280)

... 85 more

Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\web\src\project\english\target\classes\mapper\ArticlesMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert

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

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

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)

... 95 more

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.voavoice.english.dao.ArticlesMapper.insert

at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:782)

at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:754)

at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:578)

at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:288)

at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:307)

at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:127)

at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:71)

at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:651)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.bindMapperForNamespace(XMLMapperBuilder.java:405)

at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:94)

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

... 98 more

解决方案:

小编检查了一下自己的项目,发现“ArticlesMapper.xml”文件中并没有重复的两个“insert”方法,后来才发现是小编使用了通用mapper插件,因为通用mapper里面已经自带了insert方法,所以我们需要将“ArticlesMapper.xml”映射文件中的insert方法删除掉即可。

来源网站:太平洋学习网,转载请注明出处:http://www.tpyyes.com/a/javaweb/656.html
"文章很值,打赏犒劳作者一下"
微信号: Javaweb_engineer

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

与本文相关的文章

发表我的评论
取消评论

表情

您的回复是我们的动力!

  • 昵称 (必填)

网友最新评论