前言:在使用同事封装的自定义通用mapper接口工具模块时,出现扫描不到业务模块的mapper接口报出控制器、服务实现类依赖无法满足问题。
错误类似以下内容(当时并没有保存日志):
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.minibike.bike.user.dao.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}”
1.从日志得到的信息
控制器、服务实现类的依赖无法满足是因为UserMapper这个bean没有被注入(可以从该句看出:expected at least 1 bean which qualifies as autowire candidate.)
2.大致的分析
既然UserMapper这个bean没有被装配成功,那么问题可能出现在Mapper包的扫描上。(mapper包

本文记录了在SpringBoot项目中使用tk.mapper时遇到的bean注入问题,详细描述了从错误日志分析、模块结构排查到最后发现启动类目录配置不当导致MapperConfig未生效的解决过程,提醒开发者注意模块依赖及启动类位置对配置扫描的影响。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



