Springboot+Mybatis-plus运行出现java.lang.IllegalStateException: Failed to load ApplicationContext

最近初学使用mybatis-plus

在自己手写generator并运行成功之后尝试在test中使用@Autowire注解引用接口

并练习insert操作结果遇到了

java.lang.IllegalStateException: Failed to load ApplicationContext

在错误信息中发现:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addressServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.test.mapper.AddressMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.test.mapper.AddressMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

大概是无法注入Bean 导致的

检查生成器的Service类都有@Service注解,后依照参考的项目将所有的mapper类加上了@Repository与@Mapper注解,但问题依旧没有解决

后来在Test类头部加上了

@MapperScan("com.test.mapper") 

如图:

至此问题解决

项目目录大致如下:

参考贴子:https://blog.csdn.net/zhangcc233/article/details/80898931

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值