简体   繁体   中英

Spring XML list of beans

I'd like to do something like

<bean id="xxx" class="yyy">
    <property name="list">
        <list>
            <ref bean="bean1" />
            <ref bean="bean2" />
        </list>
    </property>
</bean>

The beans "bean1" and "bean2" are two different implementations of an interface I. However, they belong to different classes. Does anyone know how I can do this? I have no problem constructing a list of Strings and a list of Integers. Why can't I construct a list of beans?

Thanks,
ktm

The beans "bean1" and "bean2" are two different implementations of an interface I. However, they belong to different classes. Does anyone know how I can do this?

It should work. Try it.

(There should be no runtime type problem here because the runtime type of the list is the raw type of the implementation class used.)

I have no problem constructing a list of Strings and a list of Integers. Why can't I construct a list of beans?

I think you are assuming that it won't work without trying it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM