AreaServiceTest报错
来源:2-9 验证Sevice
Shmebulock
2021-11-16
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@b2c100] to prepare test instance [com.imooc.o2o.service.AreaServiceTest@fb309]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.imooc.o2o.service.AreaServiceTest’: Unsatisfied dependency expressed through field ‘areaService’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.imooc.o2o.service.AreaService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
尝试将Spring-service.xml文件中扫描service包下所有使用注解的的类型范围扩大(将上层语句改为下层)。问题得到解决。但是不知道为什么,况且老师视频中并没有修改扫描范围,想请问下老师可能的原因。
<!-- 扫描service包下所有使用注解的类型 -->
<context:component-scan base-package="com.imooc.service"/>
<!-- 扫描service包下所有使用注解的类型 -->
<context:component-scan base-package="com.imooc"/>
2回答
-
bug集中营
2022-04-20
一样样,改一下还真行00 -
翔仔
2021-11-16
同学好,可以看看同学的项目目录结构是否和视频里一致,如果一致,可以改成和视频一样,clean一下项目和tomcat试试。
00
相似问题