maven项目下使用context:component-scan的困惑 10
我搭建了一个javamaven项目,在运行test文件下的类时,需要扫描main下的一个文件夹下的标记了@Component的类,但是在测试类使用@Autowired时报...
我搭建了一个java maven项目,在运行test文件下的类时,需要扫描main下的一个文件夹下的标记了@Component的类,但是在测试类使用@Autowired时报无法装配的错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liu.core.workflow.WrokflowTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.liu.core.workflow.service.WorkFlowService com.liu.core.workflow.WrokflowTest.workflowService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.liu.core.workflow.service.WorkFlowService] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) 展开
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liu.core.workflow.WrokflowTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.liu.core.workflow.service.WorkFlowService com.liu.core.workflow.WrokflowTest.workflowService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.liu.core.workflow.service.WorkFlowService] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏10(财富值+成长值)
1个回答
展开全部
context:component-scan是来指定扫描哪个包下的bean,http://blog.csdn.net/chunqiuwei/article/details/16115135
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询