智者不为愚者谋,勇者不为怯者死。这篇文章主要讲述解决找不到mapper.xml文件的问题相关的知识,希望能为你提供帮助。
先看问题长啥样吧!下面是通过逆向工程生成的Mapper.xml文件,包路径什么的都没有错!
文章图片
但是每次调用Mapper中的方法的操作数据库的时候都失败:
文章图片
贴出来详细的报错信息:
文章图片
1 三月 19, 2017 10:16:45 下午 org.apache.catalina.core.ApplicationContext log 2 信息: No Spring WebApplicationInitializer types detected on classpath 3 三月 19, 2017 10:16:45 下午 org.apache.catalina.core.ApplicationContext log 4 信息: Initializing Spring root WebApplicationContext 5 三月 19, 2017 10:16:48 下午 org.apache.catalina.core.ApplicationContext log 6 信息: Initializing Spring FrameworkServlet \'xuebusi-manager\' 7 三月 19, 2017 10:20:40 下午 org.apache.catalina.core.StandardWrapperValve invoke 8 严重: Servlet.service() for servlet [xuebusi-manager] in context with path [] threw exception [Request processing failed; nested 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.selectByExample 10at org.apache.ibatis.binding.MapperMethod$SqlCommand.< init> (MapperMethod.java:189) 11at org.apache.ibatis.binding.MapperMethod.< init> (MapperMethod.java:43) 12at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58) 13at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51) 14at com.sun.proxy.$Proxy19.selectByExample(Unknown Source) 15at com.xuebusi.service.impl.UserServiceImpl.getUserById(UserServiceImpl.java:66) 16at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 17at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 18at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 19at java.lang.reflect.Method.invoke(Method.java:606) 20at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) 21at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 22at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 23at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) 24at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267) 25at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 26at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 27at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 28at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 29at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 30at com.sun.proxy.$Proxy20.getUserById(Unknown Source) 31at com.xuebusi.controller.TestController.getUserById(TestController.java:50) 32at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 33at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 34at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 35at java.lang.reflect.Method.invoke(Method.java:606) 36at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 37at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 38at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 39at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) 40at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) 41at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 42at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 43at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 44at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 45at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) 46at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) 47at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 48at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 49at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 50at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 51at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 52at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 53at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 54at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 55at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 56at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 57at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 58at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 59at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 60at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 61at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) 62at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 63at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 64at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 65at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) 66at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) 67at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) 68at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) 69at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 70at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 71at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 72at java.lang.Thread.run(Thread.java:745)
文章图片
文章图片
折腾了两天,偶尔在网上见网友如下解决方案,才算是解决了(想大哭一场):
文章图片
【解决找不到mapper.xml文件的问题】原因是:maven默认会把src/main/resources下的所有配置文件以及src/main/java下的所有java文件打包或发布到target\\classes下面,但是现实我们可能会在src/main/java下面也放置一些配置文件如hibernate配置文件或mybatis mapper配置文件等,如果不做一些额外配置,那我们打包后的项目可能找不到这些必须的资源文件,因此在pom.xml中增加类似如下配置,这样就会将src/main/java下的xml文件随同java编译后的class文件一同copy到相应的class目录。
文章图片
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>
文章图片
推荐阅读
- SpringBoot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFact
- Android 异步加载神器Loader全解析
- gradle-4.1-all.zip离线包下载 极速 android studio2.3 3.0编译必备
- Android运用Builder来创建Alertdialog
- jdk的设置及安装android studio提示does not point to a valid jvm问题
- 安装Android studio出现'tools.jar' seems to be not in Android Studio classpath......的解决方法
- 纯净版xp系统下记事本如何设置自动保存【图文详细教程】
- 萝卜家园XP系统下音量控制程序消失如何处理
- XP系统下磁盘空间变少了是怎样回事|XP系统下磁盘空间变少了的处理办法