关于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.<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>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.tld</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    
    </resources>
</build>
这样你的项目发布之后.xml文件就能一起发布了,也就解决了上面的问题




                
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值