Fix problems with Mapper.xml file not found

Source: Internet
Author: User

Let's see what the problem looks like! Here is the Mapper.xml file generated by reverse engineering, the package path is nothing wrong!

But every time you invoke the operations database of a method in mapper, it fails:

Put out detailed error message:

 1 19, 2017 10:16:45 pm Org.apache.catalina.core.ApplicationContext Log 2 info: No Spring webapplicationinitializer types  Detected on Classpath 33 months 19, 2017 10:16:45 pm Org.apache.catalina.core.ApplicationContext Log 4 info: Initializing Spring Root Webapplicationcontext 53 months 19, 2017 10:16:48 pm Org.apache.catalina.core.ApplicationContext Log 6 info: Initializing S  Pring frameworkservlet ' Xuebusi-manager ' 73 months 19, 2017 10:20:40 pm Org.apache.catalina.core.StandardWrapperValve invoke 8 Critical: Servlet.service () for Servlets [Xuebusi-manager] in the context with path [] threw exception [Request processing failed; n ested exception is org.apache.ibatis.binding.BindingException:Invalid bound statement (not found): Com.xuebusi.mapper.TbUserMapper.selectByExample] with root cause 9 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): Com.xuebusi.mapper.TbUserMapper.selectByExample10 at ORG.APACHE.IBATIS.BINDING.M Appermethod$sqlcommand.<init> (mappermethod.java:189) 11 at org.apache.ibatis.binding.mappermethod.<init> (mappermethod.java:43) at Org.apache.ibatis.binding.Mapp Erproxy.cachedmappermethod (mapperproxy.java:58) at Org.apache.ibatis.binding.MapperProxy.invoke ( mapperproxy.java:51) in Com.sun.proxy. $Proxy 19.selectByExample (Unknown Source) at Com.xuebusi.service.impl.Use Rserviceimpl.getuserbyid (userserviceimpl.java:66) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) ) at Sun.reflect.NativeMethodAccessorImpl.invoke (nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMe Thodaccessorimpl.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.SPR Ingframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint (reflectivemethodinvocation.java:190) at Org.springframework.aop.framework.ReflectiveMethodInvocation.prOceed (reflectivemethodinvocation.java:157) at Org.springframework.transaction.interceptor.transactioninterceptor$1.proceedwithinvocation ( TRANSACTIONINTERCEPTOR.JAVA:99) at Org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction ( transactionaspectsupport.java:267) at Org.springframework.transaction.interceptor.TransactionInterceptor.invoke (transactioninterceptor.java:96) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:179) at     Org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (exposeinvocationinterceptor.java:92) 28     At Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:179) 29 At Org.springframework.aop.framework.JdkDynamicAopProxy.invoke (jdkdynamicaopproxy.java:207)-at com.sun.proxy.$ Proxy20.getuserbyid (Unknown Source) at Com.xuebusi.controller.TestController.getUserById (testcontrOLLER.JAVA:50) Sun.reflect.NativeMethodAccessorImpl.invoke0 at sun.reflect.NativeMethodAcces (Native Method) Sorimpl.invoke (nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:606), at Org.springframewo Rk.web.method.support.InvocableHandlerMethod.doInvoke (invocablehandlermethod.java:221) Notoginseng at Org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (invocablehandlermethod.java:137 ) at Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( SERVLETINVOCABLEHANDLERMETHOD.JAVA:110) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod ( requestmappinghandleradapter.java:777) Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( Requestmappinghandleradapter.java:706) at Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle ( abstracthandlermethodadapter.java:85) at Org.springframework.web.servlet.DispatcherServlet.doDispatch ( dispatcherservlet.java:943) at Org.springframework.web.servlet.DispatcherServlet.doService ( dispatcherservlet.java:877) at Org.springframework.web.servlet.FrameworkServlet.processRequest ( frameworkservlet.java:966) at Org.springframework.web.servlet.FrameworkServlet.doGet (frameworkservlet.java:857 ) at Javax.servlet.http.HttpServlet.service (httpservlet.java:624) at Org.springframework.web.servlet.Framework  Servlet.service (frameworkservlet.java:842) at Javax.servlet.http.HttpServlet.service (httpservlet.java:731) Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:303) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:208) Wuyi 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:505) at Org.apache.catalina.core.StandardHostValve.invokE (standardhostvalve.java:169) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:103) Org.apache.catalina.valves.AccessLogValve.invoke at Org.apache.catalina.core.Stan (accesslogvalve.java:956) Dardenginevalve.invoke (standardenginevalve.java:116) at Org.apache.catalina.connector.CoyoteAdapter.service ( coyoteadapter.java:436) at Org.apache.coyote.http11.AbstractHttp11Processor.process ( abstracthttp11processor.java:1078) at Org.apache.coyote.abstractprotocol$abstractconnectionhandler.process ( abstractprotocol.java:625) at Org.apache.tomcat.util.net.jioendpoint$socketprocessor.run (JIoEndpoint.java:318) Java.util.concurrent.ThreadPoolExecutor.runWorker at Java.util.concurrent.Th (threadpoolexecutor.java:1145) Readpoolexecutor$worker.run (threadpoolexecutor.java:615) at org.apache.tomcat.util.threads.taskthread$ Wrappingrunnable.run (taskthread.java:61) at Java.lang.Thread.run (thread.java:745)

Tossing for two days, occasionally on the Internet to see the following solutions, only to be solved (want to cry a):

The reason: Maven defaults to packaging or publishing all of the configuration files under Src/main/resources and all Java files under Src/main/java to Target\classes, but in reality we may be in src/main/ Java below also put some configuration files such as hibernate configuration files or MyBatis mapper configuration files, etc., if you do not do some additional configuration, then our packaged project may not find these necessary resource files, So add a configuration like this in Pom.xml, which will copy the XML file under Src/main/java with the Java compiled class file to the appropriate class directory.

1     <build> 2         <resources> 3             <resource> 4                 <directory>src/main/java</ Directory> 5                 <includes> 6                     <include>**/mapper/*Mapper.xml</include> 7                 </ Includes> 8             </resource> 9         </resources>10     </build>

Fix an issue with the Mapper.xml file cannot be found

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.