老师,我做junit单元测试的时候,装载Bean报错了
来源:2-7 验证Dao
慕码人8436960
2018-04-19
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.imooc.o2o.dao.AreaDaoTest': Unsatisfied dependency expressed through field 'areaDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.imooc.o2o.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
写回答
1回答
-
翔仔
2018-04-20
同学好,出现这样的问题可能的原因是
1、AreaDao的package和spring-dao.xml里面的扫描package不一致
2、BaseTest里加载的spring-dao.xml是否正确
/** * * 配置spring和junit整合,junit启动时加载springIOC容器 * */ @RunWith(SpringJUnit4ClassRunner.class) // 告诉junit spring配置文件的位置 @ContextConfiguration({ "classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml", "classpath:spring/spring-redis.xml" }) public class BaseTest { }
032018-04-20
相似问题