简体   繁体   English

Spring XML bean列表

[英]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. Bean“ bean1”和“ bean2”是接口I的两种不同实现。但是,它们属于不同的类。 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 ktm

The beans "bean1" and "bean2" are two different implementations of an interface I. However, they belong to different classes. Bean“ bean1”和“ bean2”是接口I的两种不同实现。但是,它们属于不同的类。 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. 我认为您假设不尝试就无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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