运行结果:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.itheima.ApplicationTests': Unsatisfied dependency expressed through field 'bookDao': No qualifying bean of type 'com.itheima.dao.BookDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
1、项目结构:
mysql没有问题,整合mybatis成功连接。现在,springboot整合 Mybatis-plus 就出现无法注入bean.
在BookDao接口 加@Mapper 无法注入bean。后来,我想在 Application 的main方法主类上 @MapperScan("com.itheima.dao"),依然无法注入bean。需要在ApplicationTests测试类,测试。
请问,谁可以指点一下,什么问题么?
按照一下调整试试,如果不行,私信我远程快速搞
1、ApplicationTests 测试类前面增加一个public关键字
2、Book类是增加@TableName注解指定表明
3、ApplicationTests 中测试方法 曾public关键字
4、启动类上怎么@MapperScan注解
springboot测试环境无法注入bean问题分析及解决方案
如有帮助,望采纳
https://blog.csdn.net/qq_39893313/article/details/82945995
@MapperScan(basePackages = {"com.wochanye.mp.mapper"})
mybatis-plus:
# xml文件位置
mapper-locations:
- classpath*:com/wochanye/mp/mapper/xml/*.xml
# 实体类位置
type-aliases-package: com.wochanye.mp.entity