I have created a spring bean that contains a list of other beans, like so:
<bean name="InventoryManager" class="InvManager">
<property name="slots">
<bean class="HeadSlot" />
<bean class="ShoulderSlot" />
<!-- ... -->
</property>
</bean>
The problem, though, is that elsewhere I have used an @Autowired
annotation in another class to grab a list of all beans implementing a certain interface that some of these inner beans implement, like so:
@Autowired
public void registerInventoryHandlers( List<InvSlot> slots ) {
//... do some setup stuff with beans that implement the InvSlot interface.
}
The problem here is that apparently the "inner beans" defined in XML are not part of the @Autowired
list. However, giving all of these slot beans names and then referencing them from the XML seems unnecessary and ugly.
Is there a way to define a bean inside another bean, but not be an "inner" bean? Or is there a better way to handle this design?