卧疾丰暇豫,翰墨时间作。这篇文章主要讲述解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件相关的知识,希望能为你提供帮助。
原
解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件原文章链接:/uploads/allimg/220504/2132251333-1.jpg原本在Eclipse中好好的MAVEN项目,导入intellij idea中,服务器启动正常,但在调用userMapper接口时,报以下异常:
[java]
view plain
copy
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.beauxie.wxj.dao.UserMapper.findUserByCondition
- at org.apache.ibatis.binding.MapperMethod$SqlCommand.< init> (MapperMethod.java:178)
- 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.$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.< init> (MapperMethod.java:176)
- ... 60 more
“Invalid bound statement (not found):com.beauxie.wxj.dao.UserMapper.findUserByCondition ”,说明这个异常是在调用Mapper接口时发生的,看到这个异常时,首选想到的是配置可能出了问题,或者没有加注解,但反复检查以后,发现配置啥的都没问题,其中xml配置文件中,关于DAO层与Mapper文件的映射配置如下:
[html] view plain copy
- < !-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
- < property name="mapperLocations" value="https://www.songbingjia.com/android/classpath:com/beauxie/**/mapping/*.xml" />
配置文件没有问题,因为在Eclipse中都是正常的,查看控制台输出:
文章图片
以上的信息表示,服务器正在搜索文件以此来匹配:“com/beauxie/**/mapping/*.xml”,但最后的结果却是:
文章图片
文章图片
也就是说没有匹配到!我***,最后静下心来发现是在target目录下对应的位置找不到这个文件,然后去对应的目录下发现其他的包都在(比如controller包),就是没有mapper包(存放Mapper文件的),这让我很纳闷。最后自己百度了一下,终于找到了原因:
对于MAVEN项目,Eclipse会自动把项目srcmainjava目录下的配置文件(.xml)和资源文件(.properties)搬运到target目录下,而intellij idea默认是不会帮我们做这件事的。
解决办法:
在pom.xml文件中加入以下配置:
文章图片
对应代码如下:
[html] view plain copy
- < !--解决Intellij构建项目时,target/classes目录下不存在mapper.xml文件-->
- < resources>
- < resource>
- < directory> ${basedir}/src/main/java< /directory>
- < includes>
- < include> **/*.xml< /include>
- < /includes>
- < /resource>
- < /resources>
同样,想包含其他什么文件,比如.properties文件,再加一个< include> 标签类似的写法即可。
【解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件】做了以上工作以后,再把项目“Reimport”(右键选中项目-> Maven-> Reimport)一下,启动服务器,调用Mapper接口便不会报错了,而且target目录下对应的位置也有了mapper.xml文件。
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BeauXie/article/details/65448964
推荐阅读
- adb无法连接安卓手机
- Android之UI View与ViewGroup
- Android O 8.0,版本升级不跳转应用安装页面的完美解决
- 硬盘图标变了怎样办?WinXP电脑硬盘图标变了怎样改回来?
- WinXP系统下电脑不能打字如何处理?
- WinXP系统路由器设置端口映射的办法
- WinXP系统中Workgroup无法访问怎样办?
- WinXP如何创建本地连接?WinXP创建本地连接的处理办法
- 如何处理WinXP任务栏在右边的问题