2010-11-25 33 views
3

我有一個ProxyFactryBean是豆:春ProxyFactryBean是注射問題

<bean id="sendSingleSmsServiceProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> 
    <property name="target"> 
     <ref bean="sendSingleSmsServiceImpl" /> 
    </property> 
    <property name="proxyInterfaces"> 
     <value>com.test.SendSingleSmsService</value> 
    </property> 
    <property name="interceptorNames"> 
     <value>hibernateInterceptor</value> 
    </property> 
</bean> 

,我想這個bean注入到另一個與@Resource註解這裏是我的代碼:

@Resource 
public ProxyFactoryBean sendSingleSmsServiceProxy; 

但我得到這個例外:

org.springframework.beans.factory.BeanCreationException:創建名爲com.t的bean時出錯est.webservice.impl.SendSingleSmsImpl':注入資源依賴失敗;嵌套的例外是org.springframework.beans.factory.BeanNotOfRequiredTypeException:豆命名爲 'sendSingleSmsServiceProxy' 的類型必須是[的org.springframework.aop.framework.ProxyFactoryBean]的,但類型實際上是[$ Proxy24]

任何幫助將不勝感激。

回答

5

這是什麼ProxyFactoryBean做的錯誤理解。像FactoryBean所有implewntations,所產生的bean是不是FactoryBean的類型,但不管豆工廠生成(see Spring docs

在你的情況下,sendSingleSmsServiceProxy豆將是SendSingleSmsService類型的類型:

@Resource 
public SendSingleSmsService sendSingleSmsService; 

ProxyFactoryBean對象實際上是透明的,你看到的是它所產生的任何東西。

+0

非常感謝你,看起來像那是主要問題。我會看看春季的文檔。 – aykut 2010-11-25 12:14:33