最近在用Maven架SSM测试项目的时候遇到一个坑,一切配置正确的情况下通过mybatis访问数据库的时候报错如下:
严重: Servlet.service() for servlet [web] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.guli.mapper.UserMapper.getUserById] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.guli.mapper.UserMapper.getUserById
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)
at org.apache.ibatis.binding.MapperMethod.<init>(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.$Proxy31.getUserById(Unknown Source)
at com.guli.service.impl.UserServiceImpl.getUserById(UserServiceImpl.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method

在使用Maven构建SSM项目时,遇到Mybatis访问数据库时报'Invalid bound statement (not found)'错误。尝试在pom.xml中添加resource节点解决后,发现资源文件无法读取,且位置异常。解决方案是在pom.xml中增加特定配置,确保maven同时处理src/main/java和src/main/resources下的文件,避免mapper XML文件遗漏和资源配置问题。
最低0.47元/天 解锁文章
3011

被折叠的 条评论
为什么被折叠?



