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"})
版权声明:本文为weixin_44357065原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。