2010-11-25 7 views
3

私はProxyFactoryBean豆持っている:春ProxyFactoryBeanインジェクションの問題

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

を、私はここで@Resourceアノテーションを持つ別の一つにこのBeanを注入しようとしているが、そのために私のコードは次のとおりです。

@Resource 
public ProxyFactoryBean sendSingleSmsServiceProxy; 

しかし、私はこの例外が発生します:

org.springframework.beans.factory.BeanCreationException:名前がcom.tのBeanを作成中にエラーが発生しました。 est.webservice.impl.SendSingleSmsImpl ':リソースの依存関係の注入に失敗しました。ネストされた例外はorg.springframework.beans.factory.BeanNotOfRequiredTypeExceptionです:豆任意の

[$ Proxy24] [org.springframework.aop.framework.ProxyFactoryBean]タイプのものでなければならない 'sendSingleSmsServiceProxy' という名前が、タイプの実際ました助けに感謝します。

答えて

5

これは、ProxyFactoryBeanの誤解です。 FactoryBeanのすべてimplewntationsと同様に、生成されたBeanはFactoryBeanのタイプではありませんが、どんな豆工場の種類は、あなたのケースでは(see Spring docs

を生成し、sendSingleSmsServiceProxy BeanはタイプSendSingleSmsServiceであることを行っています。

@Resource 
public SendSingleSmsService sendSingleSmsService; 

ProxyFactoryBeanオブジェクトは何を見ることは、それが生成するものは何でもあり、効果的に透明です。

+0

ありがとうございました、それが主要な問題だったようです。私は春のドキュメントを見ていきます。 – aykut

関連する問題