org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)新的异常解决方案

首先异常如下:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.threegrand.urdm.system.dao.UserDao.saveUser
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:184)
    at org.apache.ibatis.binding.MapperMethod.<init>(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.$Proxy19.saveUser(Unknown Source)
    at com.threegrand.urdm.system.service.UserService.saveUser(UserService.java:20)
    at com.threegrand.urdm.system.service.UserService$$FastClassBySpringCGLIB$$caacda27.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:266)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
    at com.threegrand.urdm.system.service.UserService$$EnhancerBySpringCGLIB$$33d9263b.saveUser(<generated>)
    at com.threegrand.urdm.userservice.UserServiceTest.testAdd(UserServiceTest.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    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)
    。。。。

昨天下午出现的,第一次遇到这个错误,非常神奇的与网上的经验不同,他们的解决方法我都一一测试过了,还是不好使:
方案一
方案二
方案三
我主要从后面两个方案中获得灵感的,首先看我的配置,
我使用的是mybatisRepository注解,将mybatis接口注入:

  <!-- MyBatis配置 -->
    <bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:/mybatis/configuration-mybatis.xml"/>
        <!-- 显式指定Mapper文件位置 -->
        <property name="mapperLocations">
            <list>
                <value>classpath*:/mapper/UserDao.xml</value>
            </list>
        </property>
        <property name="configurationProperties">
            <props>
                <!-- mapUnderscoreToCamelCase属性将表中列名的下划线映射为JavaBean属性的驼峰式命名,默认为false -->
                <prop key="mapUnderscoreToCamelCase">true</prop>
            </props>
        </property>
    </bean>

之前使用mybatis plugins将所有潜在的错误都排查过了,当然还有启动日志,还重写了项目,并且检查了每个可能发生错误的配置,但是还是不好使,我把xml文件和Dao接口放在一个包名下,然后让注解去扫描,进行动态代理,但是依然找不到问题所在,我使用debug模式模拟方法调用还是不行。听说要将xml文件放到config-mybatis.xml中的mappers中,但是还是不好使,在idea 下的代码资源文件中和测试资源文件中都试过了,不好使,很衰的样子,我跟另一个朋友也讨论了,但是没有结果。

后来把mapper映射文件放到资源目录下,进行扫描竟然好使了。
如图:
项目结构

  • 27
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值