2021-11-07 Service层注解@Service失败原因及解决办法

2021-11-07 Service层注解@Service失败原因及解决办法,第1张

2021-11-07 Service层注解@Service失败原因及解决办法 Service层注解@Service失败原因及解决办法 直接上报错代码
Error creating bean with name 'com.mp.mybatis.MybatisApplicationTests': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.mp.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
报错原因分析:

1、Service层没有添加@Service注解

2、有@Service仍然报错

解决办法:

在SpringBoot的启动类@SpringBootApplication上添加scanbasePackages = {“com.mp.service”},扫描Service层

@SpringBootApplication(scanbasePackages = {"com.mp.service"})

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5137509.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存