mybatis简单测试问题mybatis的文件可以有mybatis.xml、mapper相关的xml、如果想把返回类型也设置成xml就可以
mybatis简单测试问题
mybatis的文件可以有mybatis.xml、mapper相关的xml、如果想把返回类型也设置成xml就可以加xx-result.xml
对于刚接触mybatis的同学们来说配置文件多,就代表有写迷糊,也容易遇到一些比较怪的问题,下边就是我今天遇到的问题
写道java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.hoo.mapper.AccountMapper.get
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:594)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:436)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:428)
at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:188)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:51)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)
at $Proxy12.get(Unknown Source)
at com.hoo.mapper.AccountMapperTest.testGetAccount(AccountMapperTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runManaged(AbstractJUnit38SpringContextTests.java:334)
at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.access$0(AbstractJUnit38SpringContextTests.java:326)
at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests$1.run(AbstractJUnit38SpringContextTests.java:216)
at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTest(AbstractJUnit38SpringContextTests.java:296)
at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTestTimed(AbstractJUnit38SpringContextTests.java:253)
at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runBare(AbstractJUnit38SpringContextTests.java:213)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 凡是出现mapper.xx执行的方法找不到的异常,其实就是mybatis没有找到mapper.xml和接口没有方法没有关系