Given this class:
public class Node {
private final List<Node> children;
public Node(){
children = new ArrayList<>();
// possibly pre-populate the list here
}
public List<Node> getChildren(){
return children;
}
}
What is the best way to create a Node with children in Spring, when some of the children are defined by the class and some should be configurable?
<bean id="node1" class="Node">
<property name="children">
<add-item><bean class="Node"/></add-item> <!--pseudocode-->
<add-item><bean class="Node"/></add-item> <!--pseudocode-->
</property>
</bean>
The answers I found in Spring IoC docs and forums didn't satisfy me because the proposed solutions involved various degrees of overhead: Additional mapping beans, factory methods, abstract beans to inherit from, ... isn't there something more elegant?