2013-06-27 12 views
5

オブジェクトのリストについてRuntimeBeanRefrenceを使用して、次のXMLを使用している場合: - クラスXとクラスYはConversionNotSupportedException我々は現在、Springフレームワークを使用している

クラスAのようにセッターを有するクラスBを拡張

<bean id="A" class="com.foo.baar.A" > 
    <property name="attributes"> 
     <set value-type="com.foo.bar.B"> 
      <ref bean="X" /> 
      <ref bean="Y" /> 
     </set> 
    </property> 
</bean> 

<bean id="X" class="com.foo.bar.X" /> 
<bean id="Y" class="com.foo.bar.Y" /> 

次の: -

public void setAttributes(List<B> attributes) { 
    this.attributes = attributes; 
} 

は今、私は上記のXMLを排除する必要があると私は次のようにプログラム的豆を設定しています: -

上記のコードでは
List<Object> beanRefrences = new ArrayList<Object>(); 
for(String attribute : attributes) { 
    Object beanReference = new RuntimeBeanReference(attribute); 
    beanRefrences.add(beanReference); 
} 
mutablePropertyValues.add(propertyName, beanRefrences); 

、私は次のようなエラーになっています: -

nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.util.List' for property 'attributes'; 
nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.beans.factory.config.RuntimeBeanReference] to required type [com.foo.bar.B] for property 'attributes[0]': no matching editors or conversion strategy found 

することは誰も私にそれを正しく動作させる方法についての指針を与えることができますか?

+0

は思えます。 – zeroflagL

+0

@DexterMorgan、あなたはそれを動作させましたか? – whiskeysierra

答えて

0

BeanDefinitionValueResolverのSpringの実装を見てみると、伝統的な普通のListでは不十分であることがわかります。あなたはManagedListを使用する必要があります:あなたは 'B'のインスタンスを設定する必要があります `RuntimeBeanReference`のインスタンスを設定するよう

List<Object> beanRefrences = new ManagedList<>(); 
for(String attribute : attributes) { 
    Object beanReference = new RuntimeBeanReference(attribute); 
    beanRefrences.add(beanReference); 
} 
mutablePropertyValues.add(propertyName, beanRefrences); 
関連する問題