1. 程式人生 > >org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)新的異常解決方案

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對映檔案放到資源目錄下,進行掃描竟然好使了。
如圖:
專案結構