关于spring+springMVC+mybatis+maven搭建中的nested exception is org.apache.ibatis.binding.BindingException

以前没用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.(MapperMethod.java:189)
	org.apache.ibatis.binding.MapperMethod.(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文件的标签中添加如下代码


    oassm
    
        
            src/main/java
            
                **/*.properties
                **/*.xml
                **/*.tld
            
            true
        
    
    
这样你的项目发布之后.xml文件就能一起发布了,也就解决了上面的问题



 
 

你可能感兴趣的:(关于spring+springMVC+mybatis+maven搭建中的nested exception is org.apache.ibatis.binding.BindingException)