Reputation: 2158
I have the bean definitions like below
<util:list id="myBeanList">
<bean id="stage1" class="Stageclass"/>
<bean id="stage2" class="Stageclass"/>
</util:list>
I know that If we want to refer the above list, we can use something like
<ref bean="myBeanList" />
But, I don't want to refer the whole list, instead i want to refer a particular bean inside this list, say "stage1". May be something like <ref bean="myBeanList$stage1" />
?
Is it possible to refer an inner bean like this? Is yes, how to do?
Upvotes: 1
Views: 731
Reputation: 2226
You can use Spring Expression Language to do this.
<ref bean="#{myBeanList[0]}" />
However, I'm not sure you'll be able to access by bean's id within the list. List will not allow you to access anything by bean id or name (that is inherently a Map kind of pattern). If you need by-name access, you should consider putting all your beans in a map and then expression language should allow you to access it by name. Here is an example of how you can access elements from map by bean id.
One reference of expression language I found is this. Take a look at how studentList is used in the spring-config.xml.
Upvotes: 1