Monthly Archives: May 2013

I’d like to show how to instantiate Spring bean with non-default constructor (constructor with parameters) from other Spring driven bean because it seems to me that a lot of Java developers don’t know that this is possible.

Next component instantiates ComponentWithParams. It needs to be aware of Spring’s context instance to be able to pass arguments non-default constructor.getBean(String name, Object... args) method is used for that purpose. First parameter of this method is name of the instantiating component (that is why component needed to be named). Constructor parameters follow.