博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件
阅读量:5859 次
发布时间:2019-06-19

本文共 13925 字,大约阅读时间需要 46 分钟。

原本在Eclipse中好好的MAVEN项目,导入intellij idea中,服务器启动正常,但在调用userMapper接口时,报以下异常:

[java]
  1. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.beauxie.wxj.dao.UserMapper.findUserByCondition  
  2.     at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:178)  
  3.     at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38)  
  4.     at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)  
  5.     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)  
  6.     at com.sun.proxy.$Proxy10.findUserByCondition(Unknown Source)  
  7.     at com.beauxie.wxj.service.impl.UserServiceImpl.validata(UserServiceImpl.java:61)  
  8.     at com.beauxie.wxj.service.impl.UserServiceImpl.validataUsername(UserServiceImpl.java:35)  
  9.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  10.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  
  11.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
  12.     at java.lang.reflect.Method.invoke(Method.java:606)  
  13.     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)  
  14.     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)  
  15.     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)  
  16.     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)  
  17.     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)  
  18.     at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)  
  19.     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)  
  20.     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)  
  21.     at com.sun.proxy.$Proxy13.validataUsername(Unknown Source)  
  22.     at com.beauxie.wxj.controller.UserController.checkUsername(UserController.java:83)  
  23.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  24.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  
  25.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
  26.     at java.lang.reflect.Method.invoke(Method.java:606)  
  27.     at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)  
  28.     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)  
  29.     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)  
  30.     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)  
  31.     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)  
  32.     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)  
  33.     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)  
  34.     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)  
  35.     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)  
  36.     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)  
  37.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)  
  38.     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)  
  39.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)  
  40.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)  
  41.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)  
  42.     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)  
  43.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)  
  44.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)  
  45.     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)  
  46.     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)  
  47.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)  
  48.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)  
  49.     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)  
  50.     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)  
  51.     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)  
  52.     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)  
  53.     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)  
  54.     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)  
  55.     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)  
  56.     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)  
  57.     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)  
  58.     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)  
  59.     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)  
  60.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
  61.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
  62.     at java.lang.Thread.run(Thread.java:745)  
  63. Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.beauxie.wxj.dao.UserMapper.findUserByCondition  
  64.     at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)  
  65.     at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615)  
  66.     at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608)  
  67.     at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:176)  
  68.     ... 60 more  
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.beauxie.wxj.dao.UserMapper.findUserByCondition    at org.apache.ibatis.binding.MapperMethod$SqlCommand.
(MapperMethod.java:178) at org.apache.ibatis.binding.MapperMethod.
(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.$Proxy10.findUserByCondition(Unknown Source) at com.beauxie.wxj.service.impl.UserServiceImpl.validata(UserServiceImpl.java:61) at com.beauxie.wxj.service.impl.UserServiceImpl.validataUsername(UserServiceImpl.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy13.validataUsername(Unknown Source) at com.beauxie.wxj.controller.UserController.checkUsername(UserController.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.beauxie.wxj.dao.UserMapper.findUserByCondition at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608) at org.apache.ibatis.binding.MapperMethod$SqlCommand.
(MapperMethod.java:176) ... 60 more
Invalid bound statement (not found):com.beauxie.wxj.dao.UserMapper.findUserByCondition ”,说明这个异常是在调用Mapper接口时发生的,看到这个异常时,首选想到的是配置可能出了问题,或者没有加注解,但反复检查以后,发现配置啥的都没问题,其中xml配置文件中,关于DAO层与Mapper文件的映射配置如下:

[html]
  1. <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->  
  2.     <property name="mapperLocations" value="classpath:com/beauxie/**/mapping/*.xml" />  
配置文件没有问题,因为在Eclipse中都是正常的,查看控制台输出:

以上的信息表示,服务器正在搜索文件以此来匹配:“com/beauxie/**/mapping/*.xml”,但最后的结果却是:

也就是说没有匹配到!我***,最后静下心来发现是在target目录下对应的位置找不到这个文件,然后去对应的目录下发现其他的包都在(比如controller包),就是没有mapper包(存放Mapper文件的),这让我很纳闷。最后自己百度了一下,终于找到了原因:

对于MAVEN项目,Eclipse会自动把项目src\main\java\目录下的配置文件(.xml)和资源文件(.properties)搬运到target目录下,而intellij idea默认是不会帮我们做这件事的。

解决办法:

在pom.xml文件中加入以下配置:

对应代码如下:

[html]
  1. <!--解决Intellij构建项目时,target/classes目录下不存在mapper.xml文件-->  
  2.        <resources>  
  3.            <resource>  
  4.                <directory>${basedir}/src/main/java</directory>  
  5.                <includes>  
  6.                    <include>**/*.xml</include>  
  7.                </includes>  
  8.            </resource>  
  9.        </resources>  
${basedir}/src/main/java
**/*.xml

这段代码的意思就是把src/main/java目录下所有的xml文件都包含进去,其中${basedir} 是MAVEN的内置变量,表示项目根目录

同样,想包含其他什么文件,比如.properties文件,再加一个<include>标签类似的写法即可。

做了以上工作以后,再把项目“Reimport”(右键选中项目->Maven->Reimport)一下,启动服务器,调用Mapper接口便不会报错了,而且target目录下对应的位置也有了mapper.xml文件。

你可能感兴趣的文章
第二节 分支结构
查看>>
php if判断条件的巧用
查看>>
在IDEA中实战Git
查看>>
设计模式读书笔记-简单工厂模式
查看>>
我的友情链接
查看>>
Shell脚本编程概述
查看>>
Java深入数组
查看>>
Mysql5.7.12/10安装配置步骤
查看>>
Minor GC安全检查
查看>>
51CTO博客数据库方面博文专题汇总
查看>>
1. 赋值运算符函数
查看>>
把二叉树打印成多行(未)
查看>>
系统文件必须同“位”
查看>>
好程序员分享JavaScript代码组织结构良好的5个特点
查看>>
论WEB服务器框架选型
查看>>
基础算法--辗转相除法
查看>>
【已解决】http400错误
查看>>
crond定时任务详细介绍
查看>>
web ssh方案Gateone
查看>>
HTML5教程:1.2 HTML 5会深受欢迎的理由
查看>>