2010-11-25 8 views
3

J'ai un haricot ProxyFactoryBean:Spring ProxyFactoryBean injection Problème

<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> 

et je suis en train d'injecter ce haricot dans l'autre avec l'annotation @Resource ici est mon code pour que:

@Resource 
public ProxyFactoryBean sendSingleSmsServiceProxy; 

mais j'obtiens cette exception:

org.springframework.beans.factory.BeanCreationException: Erreur lors de la création du bean avec le nom 'com.t est.webservice.impl.SendSingleSmsImpl ': L'injection des dépendances de ressources a échoué; exception imbriquée est org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean nommé 'sendSingleSmsServiceProxy' doit être de type [org.springframework.aop.framework.ProxyFactoryBean], mais était en fait de type [$ Proxy24]

tout l'aide serait appréciée.

Répondre

5

Ceci est une mauvaise compréhension de ce que fait ProxyFactoryBean. Comme tous les implewntations de FactoryBean, le haricot qui est généré est pas le type de FactoryBean, mais le type de tout grain de l'usine génère (see Spring docs)

Dans votre cas, le haricot sendSingleSmsServiceProxy va être de type SendSingleSmsService:

@Resource 
public SendSingleSmsService sendSingleSmsService; 

ce que vous voyez le objet ProxyFactoryBean est effectivement transparent, est tout ce qu'il génère.

+0

merci beaucoup, on dirait que c'était le problème principal. Je vais jeter un coup d'œil aux documents du printemps. – aykut