新手-springboot-实战启动-找不到mapper的bean

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ProductionController': Unsatisfied dependency expressed through field 'ProductionService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ProductionServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'xxx.xx.demo.mapper.ProductionMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

报错:

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“ProductionController”的bean时出错:通过字段“ProductionService”表示不满意的依赖;org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“ProductionServiceImpl”的bean时出错:不满意的依赖关系通过字段“baseMapper”表示;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'xxx.xx.demo.mapper.ProductionMapper'的合格bean可用:期望至少有一个bean符合自动候选资格。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方案:
springboot启动类上加上@MapperScan(包路径)

解析:

通过在 Spring Boot 项目中使用 @MapperScan 注解,可以将 MyBatis 的 Mapper 接口自动注册到 Spring 容器中,在业务代码中直接注入和使用这些 Mapper 接口,而无需手动实例化。这样可以方便地使用 MyBatis 进行数据库操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值