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 @ 2022-05-15 22:08  唐同学  阅读(400)  评论(0编辑  收藏  举报