spring boot, maven项目,利用mybatis 注解的方式查询mysql。
业务逻辑关系:controller --> Service接口 ----> serverImpl —>Dao -->DaoImpl —> mapper -->db
问题:mapper提示Could not autowire. No beans of … type found?如图:
解决方法
在@Autowired加(required=false)
编译通过,问题解决,找了下原因,大概就是
当使用@Autowired注解的时候,其实默认就是@Autowired(required=true),表示注入的时候,该bean必须存在,否则就会注入失败。@Autowired(required=false):表示忽略当前要注入的bean,如果有直接注入,没有跳过,不会报错。
————————————————
原文链接:https://blog.csdn.net/weixin_39973810/article/details/83722356