2017-06-05 44 views
2

我在我的war文件的lib文件夹下放了一个jar文件。在jar里面,我有一些使用@Autowired fileds的类。罐子里面,ApplicationContext中的XML我已经给注入自动装配的依赖关系在jar文件中失败

<context:component-scan base-package="com.main.java.mypath" /> 

代码:

package com.main.java.mypath.client; 

@Component 
public class ServiceProvider { 

    @Autowired 
    private StoreField storeField; 




package com.main.java.mypath.data; 
public interface StoreField { 
} 

错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.main.java.mypath.data.StoreField com.main.java.mypath.client.ServiceProvider.storeField; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.main.java.mypath.data.StoreField] 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)} 
+0

你有*注射类型'StoreField'的候选人吗? – luk2302

+0

您在StoreField实施中使用了哪些软件包? – dvelopp

+0

'StoreField'是根据定义的接口。你有没有在任何课程上实现这个接口?接口不能自动布线。你需要一个自动装配类。 –

回答

3

这是不可能的,只要你不注入的依赖”您的接口可以实现您的StoreField接口。确保它是作为一个类实现的,并且在spring上下文中通过xml或annotation正确初始化。

+0

谢谢..我只是错过了它.. – NaaN

相关问题