错误如下:
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层都是用注解实现的,现在的情况是从页面发送请求就没事,但是我直接用上面的测试代码就报错。