没有自动连线
在我的测试类中,我收到 org.springframework.beans.factory.BeanCreationException: 创建名为 'com.abc.service.ExportServiceTest' 的 bean 时出错:自动装配依赖项注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: 无法自动装配字段: private com.bankbazaar.service.ExportService com.abc.service.ExportServiceTest.exportClient;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到依赖项的 [com.abc.service.ExportService] 类型的匹配 bean:预计至少有 1 个有资格作为此依赖项的自动装配候选者的 bean。依赖注释: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=exportClient)}
这是我的 spring 配置
然而
exportClient=(ExportService)applicationContext.getBean("exportClient");
这有效。
谢谢 希芒舒
I am trying to build a restful client using jaxrs:client as defined in http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
In my test class I am getting org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.abc.service.ExportServiceTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.bankbazaar.service.ExportService com.abc.service.ExportServiceTest.exportClient; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.abc.service.ExportService] 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), @org.springframework.beans.factory.annotation.Qualifier(value=exportClient)}
this is my spring config
However
exportClient=(ExportService)applicationContext.getBean("exportClient");
this works.
Thanks
Himangshu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个 ExportService 的完全限定类名
com.abc.service.ExportService
与com.bankbazaar.service.ExportService
看起来不同。将两者修复为指向相同的名称应该可以解决问题。检查通过 applicationContext.getBean() 定义的 ExportService 的包名称以确定差异。The fully qualified classname for the two ExportService looks different
com.abc.service.ExportService
vscom.bankbazaar.service.ExportService
. Fixing the two to point to the same name should fix the problem. Check the package name of the ExportService defined via applicationContext.getBean() to acertain the difference.