解決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 執行單元測試檔案時需要先儲存再執行!!!
相關文章
- Result Maps collection already contains value for com.xxx.xxxMapper.BaseResultMap問題解決AIAPP
- mybatis(錯誤) 專案啟動時報“Result Maps collection already contains value forxxx”的解決方案MyBatisAI
- Result Maps collection already contains value for xxx.xxx.dao.BaseResultMap錯誤AI
- Maven建立SSM專案 啟動時報錯Mapped Statements collection does not contain value for xxxMavenSSMAPPAI
- 解決 eclipse出現 Address already in use: bindEclipse
- @AllArgsConstructor與@Value共用的問題解決Struct
- SpringBoot整合mybatis出現時區問題Spring BootMyBatis
- 解決Ubuntu配置nginx出現的問題UbuntuNginx
- 快速解決mongodb出現id重複問題MongoDB
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- iOS 解決tableHeaderView新增searchBar後出現的問題iOSHeaderView
- kafka監聽出現的問題,解決和剖析Kafka
- 同時使用mybatis和mybatis-plus時,pageHelper失效問題解決MyBatis
- Mybatis入門 Mybatis存在的意義 解決的問題 基本操作MyBatis
- 解決Mybatis連線Sql server 出現 Cannot load JDBC driver class 'com.mysql.jdbc.Driver '的問題MyBatisServerJDBCMySql
- 解決ProtocolHandler ["ajp-nio-8009"] java.net.BindException: Address already in use: bind問題ProtocolJavaIndexException
- 解決出現This system is not registered to Red Hat Subscription Management的問題
- 換IP經常出現的問題及其解決方案
- list is not in GROUP BY clause and contains nonaggre的問題AI
- 有趣的 events_statements_current 表問題
- wordress小程式圖片訪問出現404問題解決辦法
- PySimpleGUI 引入後VsCode出現問題提示 “could not be resolved” 解決方案GUIVSCode
- Java swing JFrame用repaint出現閃爍的問題解決JavaAI
- 驚群問題|復現|解決
- ISSAC GYM解決RuntimeError: nvrtc: error: invalid value for --gpu-architecture (-arch)的問題ErrorVRGPU
- @Value失效的問題
- cat 輸出亂碼問題解決
- 解決 mybatis一對多分頁問題 聯級查詢MyBatis
- unity 3D音 釋出PICO後出現問題的解決方法Unity3D
- 關於網路硬體配置出現問題,無法上網問題的解決
- Mybatis-技術專區-如何清晰的解決出現「多對一模型」和「一對多模型」的問題MyBatis模型
- Ubuntu出現“E: 無法定位軟體包問題”解決方法Ubuntu
- npm install報錯、失敗,出現network proxy問題解決方案NPM
- Win10系統下BATTLETECH出現問題的解決方法Win10BAT
- 【Debian】更換軟體 源出現的Certificate問題解決方法
- 在IDEA下使用JUnit出現的問題與解決辦法Idea
- java專案解決SLF4J: Class path contains multiple SLF4J bindings.問題JavaAI
- MyBatis 解決欄位名不一致的問題MyBatis