I have a class like this –
class Messages
{
...
LinkedList<String> inputs;
LinkedList<String> outputs;
...
}
Normally, I would initialize inputs and outputs in the constructor –
public Messages()
{
inputs = new LinkedList<String>();
outputs = new LinkedList<String>();
}
However, I want to achieve the same result using spring configuration. So what should I put under the following node?
<bean id="Messages" class="com.somename.Messages">
<--- what goes here?
</bean>
When the Spring Container creates the “Messages” bean, will it call the constructor also?
Yes, it will call the constructor. It would be very odd for an IoC container not to call a constructor – it would have to go to some lengths to construct an instance of the object without going through a constructor, and it would almost always be a bad idea.
Of course, you can also initialize your variables as part of the declaration: