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

來源:互聯網
上載者:User

首先異常如下:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.