2 qq 25826421 qq_25826421 于 2016.03.18 15:13 提问

spring依赖注入测试时出错

错误如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'analysisService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.gbicc.dao.AnalysisMapper com.gbicc.service.AnalysisServiceImpl.analysisMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.gbicc.dao.AnalysisMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

我写的测试代码如下:
public class test {
@Test
public void maintest() {
ApplicationContext appContext = new ClassPathXmlApplicationContext("/spring.xml");
//ApplicationContext appContext = new AnnotationConfigApplicationContext("com.gbicc.service");
BlackListService bsi = appContext.getBean(BlackListService.class);

//BlackListServiceImpl bsi = new BlackListServiceImpl();
String bsmap = bsi.queryDictMap("dep01");
System.out.println(bsmap);
}
}
dao层和service层都是用注解实现的,现在的情况是从页面发送请求就没事,但是我直接用上面的测试代码就报错。

1个回答

u013772876
u013772876   2016.03.18 15:19

analysisService和这个类的实现还有实现类中引用的类检查下标签是否多写了!

u013772876
u013772876 回复qq_25826421: 发下你的spring.xml文件看看!
一年多之前 回复
qq_25826421
qq_25826421 主要是正常能够运行,但是我就写了一个测试类方法就不行了,有点不理解
一年多之前 回复
qq_25826421
qq_25826421 @Service("analysisService") public class AnalysisServiceImpl implements AnalysisService { @Autowired private AnalysisMapper analysisMapper; @Autowired private BlackListMapper blackListMapper;
一年多之前 回复
qq_25826421
qq_25826421 @Service("analysisService") public class AnalysisServiceImpl implements AnalysisService { @Autowired private AnalysisMapper analysisMapper; @Autowired private BlackListMapper blackListMapper;
一年多之前 回复
qq_25826421
qq_25826421 @Service("analysisService") public class AnalysisServiceImpl implements AnalysisService { @Autowired private AnalysisMapper analysisMapper; @Autowired private BlackListMapper blackListMapper;
一年多之前 回复
qq_25826421
qq_25826421 @Service("analysisService") public class AnalysisServiceImpl implements AnalysisService { @Autowired private AnalysisMapper analysisMapper; @Autowired private BlackListMapper blackListMapper;
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!