I have a BeanA which whose constructor requires BeanB.
Once BeanB has been instantiated (and its properties set), I’d like to invoke BeanB.init()
Is there a way of doing this?
An alternative would be to have BeanB.init() invoked after all beans in the context have been created.
Cheers!
You can use
init-methodin yourapplicationContext.xmlin order to specify an init method. If you want a bean to instantiate after another, you can usedepends-on, even though anyrefelement (in this example insideconstructor-args) will implicitly place a dependency.This would initialize firstly Bean B with an
initmethod and, when finished, use it in as constructor argument to A.