记录一次使用Mybatis注解错误引发的异常
2023-09-10 00:03:13.994 ERROR 15160 — [nio-8080-exec-3] 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): com.example.service.SomeService.queryUserByList] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.service.SomeService.queryUserByList
错误异常显示Mybatis与Service类之间的某种关系绑定异常,一开始我是顺着Service去找,结果没发现还没进去SomeServiceImpl就开始报错,以为是SomeService层问题,后来证实思路是错的
@Autowired
private SomeDao someDao; //原来是走到这一行就已经报错的,愿意原因是mybatis框架找不到这个bean
@Override
public List<User> queryUserByList() {
return someDao.selectAll();
}
而出错的地方就是:没有指定包地址
//@MapperScan("com.example.dao") //正确写法
@MapperScan() //错误写法
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
虽然后续这问题看着简单多了,跟错误提示也能对上关系,这也算不标准写法的一个小坑吧