2011-01-21 1 views
2

プロパティ選択可能なトランスポートプロトコルを使用するプロキシビーンを使用しています。私の問題は、Beanのプロパティは変換できないということですが、なぜそれが本当にわかりません。これは状況です:春にプロキシオブジェクトを配線する方法は?

マイプロパティ:service.protocol = RMI

<!-- This is the 'multiplexing' factory bean (using this because properties 
cannot be used in bean names and aliases --> 

    <bean name="dbFormGenWindowComponent" 
    class="org.springframework.beans.factory.config.BeanReferenceFactoryBean"> 
    <property name="targetBeanName" value="dbFormGenWindowComponent-${service.protocol}invoker" /> 
</bean> 

<!-- Here are the service invoker beans with two protocols: --> 

    <bean name="dbFormGenWindowComponent-rmiinvoker" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> 
<property name="serviceUrl" value="${ringwindow.serviceURL.rmi}/${ringwindow.service.name}-dbFormGenWindowComponent"/> 
<property name="serviceInterface" value="foo.bar.service.formgen.windows.FormGenWindowComponent" /> 
<property name="lookupStubOnStartup" value="false"/> 
    </bean> 

起動時に例外がある:

org.springframework.beans.TypeMismatchException : [$ Proxy541]タイプのプロパティ値を必須に変換できませんでしたプロパティ 'formGenWindowComponent'には [foo.bar.service.formgen.windows.FormGenWindowComponent] を入力してください。 ネストされた例外は java.lang.IllegalArgumentExceptionがありません: は、プロパティのために必要なタイプ [foo.bar.service.formgen.windows.FormGenWindowComponent] に[$ Proxy541]タイプ の値を変換できません 'formGenWindowComponent': 一致する編集者または変換 の戦略が見つかりました

入れ子のファクトリーBeanはうまく動作するはずです。この仕事をどうやって手に入れるか考えていますか?

答えて

3

これは通常、インジェクションポイントタイプをインターフェイスではなく具象クラスに定義したが、インターフェイスに基づいてプロキシする場合に発生します。例えば:工場豆の場合

public interface Foo { .. } 
public class FooImpl { .. } // this is declared as bean 

public class Bar { 
    private FooImpl foo; // this fails 
    private Foo foo; // correct way 
} 

これは、具体的なクラスとして定義される、工場Beanの戻り型に起因し得ます。あなたはクラスで何も変更できない場合は、により、CGLIB・プロキシを使用するように、スプリングを設定することができます: - Bean定義内 -

  • <aop:scoped-proxy>これは豆
  • <aop:aspectj-autoproxy proxy-target-class="true">のプロキシを設定します - これを変更しますグローバルに
+0

私が言ったことは、私のプロキシはインターフェイスのもので、プラグインされたBeanもインターフェイスのgetter/setterを宣言しています。しかしこれを調べてみると、私のすべてのBeanReferenceFactoryBeansは同じプロキシを指している、これは本当の問題でした。私はすべてのClassCastExceptionsが非常に同じ番号のプロキシオブジェクトについて苦情を言いました。:-(あなたの種類の助けに感謝Bozho! – jb33

関連する問題