2017-06-05 147 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

相關問題