Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value

整合spring+mybatis 报错以下错误:

我完全是IDEA的问题!!!找了半天啊!!!

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wechat.module.personal.dao.UserMapper.selectAllUser

    at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:178)
    at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:38)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)
    at com.sun.proxy.$Proxy28.selectAllUser(Unknown Source)
    at com.wechat.module.personal.service.impl.UserServiceImpl.getAllUsers(UserServiceImpl.java:47)
    at com.wechat.module.personal.service.impl.UserServiceImpl$$FastClassBySpringCGLIB$$6bb9a41c.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
    at com.wechat.module.personal.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$5ad12f2.getAllUsers()
    at DBTest.testBuildDB(DBTest.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.wechat.module.personal.dao.UserMapper.selectAllUser
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)
    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615)
    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608)
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:176)
    ... 49 more

重点是:
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for
这两句报错信息,查了很久许多博客论坛都说是mapper.xml里的namespace报错 或者是方法名报错,但是看了一下午确认了并没有任何对应错误。
而且同一个项目在eclipse跑不报错。
所以开始怀疑并没有扫描到包里的XML文件。

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value_第1张图片

http://blog.csdn.net/XiWenRen/article/details/49101605
这个博客给了我提醒 提到了IDEA的扫描机制,如果在java/main 中的xml文件会被忽略 。于是可以看到 target文件夹中,并没有xml存在。
尝试了博主说的把xml直接拖到resourse,运行!


成功了!!!

但是这个方法 ,其实破坏了包结构。

尝试新的方法:不需要移动mapper.xml,推荐在pom文件中找到

<build>build>

在其中添加以下几行,用于扫描到xml文件。

<resources>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.xmlinclude>
                includes>
            resource>
resources>

-再次运行!可以成功!

你可能感兴趣的:(mybatis)