2013-08-09 2 views
2

ApplicationContextAware 인터페이스를 사용하여 ApplicationContext에 일부 스프링 빈을 동적으로 등록하려고합니다. BeanDefitionBuilder를 사용하여 Bean 정의를 작성하고이를 DefaultListableBeanFactory.registerBeanDefinition()으로 등록합니다. 지금은 XML이 같을 것이다 구축을 위해 노력하고있어 콩 :빈 정의에 동적으로 빈 참조 목록 추가

<bean id="compositeBean" class="SomeClass"> 
<property name="checks"> 
    <list> 
     <ref bean="bean1"/> 
     <ref bean="bean2"/> 
     <ref bean="bean3"/> 
    </list> 
</property> 
</bean> 

나는 가능한 위 (bean1을, bean2, bean3)에 대한 BeanDefinitions의 목록을 가지고있다. 내가 오류

org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'compositeBean': Initialization of bean 
failed; nested exception is 
org.springframework.beans.ConversionNotSupportedException: Failed to 
convert property value of type 
'org.springframework.beans.factory.config.BeanDefinition[]' to 
required type 'SomeClass[]' for property 'checks'; nested exception is 
java.lang.IllegalStateException: Cannot convert value of type 
[org.springframework.beans.factory.support.GenericBeanDefinition] to 
required type [SomeClass] for property 'checks[0]': no matching 
editors or conversion strategy found 

로 끝날

BeanDefinitionBuilder.genericBeanDefinition(SomeClass.class) 
       .addPropertyValue("checks", checks); 

사용하려고하면 프로그래밍 방식으로 내 compositeBean에 콩 참조 목록을 추가 할 수 있습니까?

답변

2

<util:list/>이 목록을 컴파일하는 데 사용하는 무엇 org.springframework.beans.factory.support.ManagedList

를 살펴 보자. 변수를 "확인"하고 해당 객체를 속성 값으로 설정하면 ManagedList를 만듭니다.

+0

감사합니다. – enpo