2013-06-27 20 views
5

nesnelerin bir listesi için RuntimeBeanRefrence kullanarak ve aşağıdaki XML kullanırken: - sınıfı X ve sınıf-YConversionNotSupportedException şu anda yay çerçevesi kullanan

sınıf A olarak ayarlayıcı sahip B sınıfı uzanan

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

aşağıdaki gibidir: -

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

Şimdi, yukarıdaki XML ortadan kaldırmak için var ve şu şekilde programlama yoluyla fasulye kuruyorum: -

Yukarıdaki kod ile
List<Object> beanRefrences = new ArrayList<Object>(); 
for(String attribute : attributes) { 
    Object beanReference = new RuntimeBeanReference(attribute); 
    beanRefrences.add(beanReference); 
} 
mutablePropertyValues.add(propertyName, beanRefrences); 

, ben hata aşağıdaki alıyorum: -

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 

kimse bana nasıl doğru çalışması için işaretçiler verebilir misiniz?

+0

görünüyor: Bir ManagedList kullanmak gerekir. – zeroflagL

+0

@DexterMorgan, işe yaradı mı? – whiskeysierra

cevap

0

BeanDefinitionValueResolver'un Spring'in uygulanmasına bir göz attıktan sonra, geleneksel, sıradan bir List'un yeterli olmadığını görebilirsiniz. Eğer B` `örneğini belirlesin RuntimeBeanReference`` örneğini ayarlamak gibi

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