org.springframework.beans.factory.UnsatisfiedDependencyException:个人解决办法

跟着视频学习mybatisPlus时候

执行测试代码,出现报错

 

org.springframework.beans.factory.UnsatisfiedDependencyException:

  Error creating bean with name 'com.tang.mybaitsplus.MyBatisPlusServiceTest': Unsatisfied dependency expressed through field 'userService';

  nested exception is org.springframework.beans.factory.

  NoSuchBeanDefinitionException: No qualifying bean of type 'com.tang.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate.

  Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 

 

原因是.创建com.tang.service.UserService实例时,没有找到userService对象,实际就是没有扫描包

在MybaitsplusApplication文件中添加service包扫描代码

 

@SpringBootApplication
@MapperScan("com.tang.mapper")
@ComponentScan("com.tang.service")//添加service扫描包代码

public class MybaitsplusApplication {

public static void main(String[] args) {
SpringApplication.run(MybaitsplusApplication.class, args);
}

}

问题解决

posted @   唐同学  阅读(483)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示