mybatis 报错 Invalid bound statement (not found)

  • Post author:
  • Post category:其他


在使用springMVC 和 mybatis 集成时,报如下错误:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wechatlearning.permission.service.RoleService.save
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:223)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy20.save(Unknown Source)
	at com.wechatlearning.permission.controller.RoleController.aaa(RoleController.java:29)
	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.doInvoke(InvocableHandlerMethod.java:221)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)

在网上找到很多解决办法,基本上都是检查 namespace 是否写错这样的办法,检查了N遍,也没发现问题,后来终于在这里找到解决办法:

https://my.oschina.net/psuyun/blog/464851


具体原因如下:

报错的配置:

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.wechatlearning" />
	</bean>

修改后的配置:

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.wechatlearning.*.dao" />
	</bean>

修改后不会再报错,是因为前面的配置在扫描时把 service 也扫描进去了。



版权声明:本文为Moneywa原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。