转:http://blog.csdn.net/v19freedom/article/details/69855302
转:http://blog.csdn.net/miaoy220/article/details/53447277
转:http://blog.csdn.net/yehanwei163/article/details/77165130
转:http://blog.csdn.net/shifangwannian/article/details/48882201
搭建一个SSM框架,项目结构如下:
然后部署并启动项目后,总是报一个错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
09-Apr-2017 17:42:20.864 严重 [http-nio-8080-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.runtu.dao.UserMapper.selectUserById] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.runtu.dao.UserMapper.selectUserById
at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:189)
at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:43)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
at com.sun.proxy.$Proxy17.selectUserById(Unknown Source)
at com.runtu.service.UserService.selectUserById(UserService.java:17)
at com.runtu.controller.UserController.getIndex(UserController.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:178)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这个问题很常见一般的原因是Mapper interface和xml文件的定义对应不上,但是我检查了包名,namespace,方法名称,还要spring的配置,都没有问题。最后发现编译后的目录没有mapper的xml,所以这边断定xml没有编译进去。
后来上网搜了下,别人给出的答复
idea在build工程的时候 遇到maven项目 使用的是pom文件里面配置的 里面的东西
而这里面如果不做特别配置 是maven默认的 编译的时候 只搬运src/main/java里面的java文件到target/classes,其他文件会被忽略
解决办法就是向maven-resources-plugin插件增加配置
http://bbs.csdn.net/topics/391841282?page=1#post-402070612 这个里面有配置的全文
这样配置之后 idea在build的时候 或者执行 maven test 的时候 才能把源码文件夹里的xml文件与java文件一起搬到target/classes 里面去
别人如果导入你的这个maven工程 也不用设置idea了
另外 为什么在eclipse里面 即使pom不做这个特别配置 也没问题 原因是eclipse在build工程的时候 不依赖 maven的pom文件 用的eclipse的编译机制 不会忽略源码文件夹里面的xml文件
下面有两种常用的方法可任选一种。
方法1,利用maven-resources-plugin插件
maven-resources-plugin
2.6
copy-xmls
process-resources
copy-resources
${basedir}/target/classes
${basedir}/src/main/java
**/*.xml
方法2,其中*/这样的写法,是为了保证各级子目录下的资源文件被打包。
test
src/main/resources
**/*.properties
**/*.xml
**/*.tld
false
src/main/java
**/*.properties
**/*.xml
**/*.tld
false