解決mybatis出現Mapped Statements collection already contains value for問題
今天看黑馬的mybatis視訊時跟著敲程式碼發現一直出現這個問題,弄了10多分鐘,終於弄出來了
錯誤原因如下
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in mybatis/user.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for user.getUserById
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
at Test.MybatisTest.testGetUserById(MybatisTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for user.getUserById
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
... 25 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for user.getUserById
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
... 27 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for user.getUserById
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.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:107)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
... 30 more
錯誤的原因是 同一個mapper.xml中存在兩個多個相同的statement的id
刪了後就能成功的執行了
然後發現一個問題,eclipse執行單元測試檔案的時候如果配置檔案修改後沒有及時儲存,那麼單元檔案會用原來的配置檔案(初學,有不當之處請大佬改正)
eclipse 執行單元測試檔案時需要先儲存再執行!!!
相關文章
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value forJavaExceptionAPPAI
- Result Maps collection already contains value for com.xxx.xxxMapper.BaseResultMap問題解決AIAPP
- mybatis(錯誤) 專案啟動時報“Result Maps collection already contains value forxxx”的解決方案MyBatisAI
- Maven建立SSM專案 啟動時報錯Mapped Statements collection does not contain value for xxxMavenSSMAPPAI
- mabatis報錯 Result Maps collection already contains value for gamedataserver.dao.one.ChargeRecordMapper.BaseResultMapBATAIGAMServerAPP
- Result Maps collection already contains value for xxx.xxx.dao.BaseResultMap錯誤AI
- @AllArgsConstructor與@Value共用的問題解決Struct
- 解決 eclipse出現 Address already in use: bindEclipse
- 解決Ubuntu配置nginx出現的問題UbuntuNginx
- 發現問題,解決問題
- 快速解決mongodb出現id重複問題MongoDB
- 解決mysql出現幾個l的問題MySql
- PHP出現Cannotmodifyheaderinformation問題的解決方法PHPHeaderORM
- SpringBoot整合mybatis出現時區問題Spring BootMyBatis
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- kafka監聽出現的問題,解決和剖析Kafka
- Gentoo startx出現Failed to load module問題解決AI
- junit測試出現的小問題解決方案
- Mybatis入門 Mybatis存在的意義 解決的問題 基本操作MyBatis
- 同時使用mybatis和mybatis-plus時,pageHelper失效問題解決MyBatis
- 解決出現This system is not registered to Red Hat Subscription Management的問題
- iOS 解決tableHeaderView新增searchBar後出現的問題iOSHeaderView
- 換IP經常出現的問題及其解決方案
- 表單傳值出現亂碼問題解決方案
- Android 解決Activity切換時出現白屏問題Android
- Android解決Activity切換時出現白屏問題Android
- 演示PPT文件時常出現的問題與解決
- 解決Mybatis連線Sql server 出現 Cannot load JDBC driver class 'com.mysql.jdbc.Driver '的問題MyBatisServerJDBCMySql
- 解決「問題」,不要解決問題
- 解決 csrf_field () 渲染後_token 的 value 為空的問題
- wordress小程式圖片訪問出現404問題解決辦法
- VS2013出現問題及解決辦法
- 解決app中多語音出現的衝突問題APP
- 解決 mybatis一對多分頁問題 聯級查詢MyBatis
- 驚群問題|復現|解決
- cat 輸出亂碼問題解決
- unity 3D音 釋出PICO後出現問題的解決方法Unity3D
- Mybatis-技術專區-如何清晰的解決出現「多對一模型」和「一對多模型」的問題MyBatis模型