org.apache.ibatis.binding.BindingException: Invalid bound statement
1. Problem screenshot:
2018-12-27 22:08:18.976 ERROR 42512 --- [nio-8090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : 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): catchm.dao.SysUserDao.insert] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx.dao.xxxDao.insert
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65) ~[mybatis-3.4.6.jar:3.4.6]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) ~[mybatis-3.4.6.jar:3.4.6]
at com.sun.proxy.$Proxy63.insert(Unknown Source) ~[na:na]
at catchm.service.impl.SysUserServiceImpl.insert(SysUserServiceImpl.java:24) ~[classes/:na]
at catchm.inte.api.sys.userApi.create(userApi.java:33) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
2. Way of resolution:
Current relevant configuration:
Application.java
@MapperScan("xxx.dao")
@SpringBootApplication(scanBasePackages = "xxx")
public class XXXApplication{
public static void main(String[] args){
SpringApplication.run(XXXApplication.class, args);
}
}
application.yml
mybatis:
mapper-locations: classpath*:xxx/mybatis/*Mapper.xml
project catalog
+ Module1
- Application and config
+ Module2
+ src
+ main
+ java
+ xxx.dao
- nameDao.java
+ resources
+ xxx.mybatis
- nameMapper.xml
Analysis of the problem found that mapperInterface(dao) had been obtained, but it was unable to connect to mapper, so it was mapper that had a problem in configuration, and resource path was an error:
- modify
application.yml
:xxx/mybatis
toxxx.mybatis
, because the former is the way to writesource root
path, but mapper belong toresource root
. I use idea, and the package name format is very similar!
mybatis:
mapper-locations: classpath*:xxx.mybatis/*Mapper.xml
3. Tips:
- Resource reference is different from the package reference;
- I’m ashamed of my carelessness and write this article.