如何在 Spring 中定義 List bean? - How to define a List bean in Spring?

問題:

I'm using Spring to define stages in my application.我正在使用 Spring 在我的應用程序中定義階段。 It's configured that the necessary class (here called Configurator ) is injected with the stages.它被配置爲必要的類(這裏稱爲Configurator )注入了階段。
Now I need the List of Stages in another class, named LoginBean .現在我需要另一個名爲LoginBean類中的階段列表。 The Configurator doesn't offer access to his List of Stages. Configurator器不提供對他的階段列表的訪問。

I cannot change the class Configurator .我無法更改Configurator類。

My Idea:我的點子:
Define a new bean called Stages and inject it to Configurator and LoginBean .定義一個名爲 Stages 的新 bean 並將其注入ConfiguratorLoginBean My problem with this idea is that I don't know how to transform this property:我這個想法的問題是我不知道如何轉換這個屬性:

<property ...>
  <list>
    <bean ... >...</bean>
    <bean ... >...</bean>
    <bean ... >...</bean>
  </list>
</property>

into a bean.成豆。

Something like this does not work:像這樣的東西不起作用:

<bean id="stages" class="java.util.ArrayList">

Can anybody help me with this?有人可以幫我解決這個問題嗎?


解決方案:

參考一: https://en.stackoom.com/question/A8We
參考二: https://stackoom.com/question/A8We
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章