關於spring+springMVC+mybatis+maven搭建中的nested exception is org.apache.ibatis.binding.BindingException
阿新 • • 發佈:2019-01-04
以前沒用maven的時候啥都很好,但是現在專案使用了maven,我也就把專案轉換成了maven的方式。
專案中的mybatis使用的是mapper代理的方式進行開發,專案未遷移之前可以正常執行,但是遷移之後就一直報一個錯誤,
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.dsr.oa.mapper.UserMapper.selectByPrimaryKey org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189) org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:43) org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58) org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51) com.sun.proxy.$Proxy12.selectByPrimaryKey(Unknown Source) com.dsr.oa.service.impl.UserServiceImpl.selectByPrimaryKey(UserServiceImpl.java:34) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) com.sun.proxy.$Proxy15.selectByPrimaryKey(Unknown Source) com.dsr.oa.controller.UserController.selectByPrimaryKey(UserController.java:21) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:624) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
剛開始我以為是我在遷移的過程中不小心改了程式碼,但是經過一遍遍的程式碼走讀,按照mapper代理的風格要求查了好幾遍卻沒有發現任何錯誤,後來開啟taget目錄看了一下
發現了問題,
我的UserMapper.xml檔案竟然沒有,這就是問題所在。maven的java程式碼資料夾中預設不編譯.xml檔案,也就是說你的專案釋出之後
java資料夾中的.xml檔案根本就不釋出,解決方案如下
在你的pom.xml檔案的<build></build>標籤中新增如下程式碼
<build> <finalName>oassm</finalName>這樣你的專案釋出之後.xml檔案就能一起釋出了,也就解決了上面的問題<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.tld</include></includes> <filtering>true</filtering> </resource> </resources> </build>