关于springboot整合mybatis出现Could not autowire. No beans of 'UserDao' type found. 的问题

598 阅读1分钟

当启动测试类@Autowired继承dao层方法时会发现private的对象报错但是并不影响使用

在这里插入图片描述 虽然不影响使用但是看着着实闹心,针对这个情况主要有两种解决办法

  1. 在dao层加入注解@Repository添加到spring容器中,虽然我使用springboot使用mapper已经将其添加到容器中了,但是idea仍然不解析在这里插入图片描述
  2. 第二种方法就是在测试类中不使用@Autowired注解改成@Resource注解,在dao层也不需要添加@Repository也不会报红 在这里插入图片描述