I need to create an Object which is in-complete without the constructor argument. Something like this
Class A {
private final int timeOut
public A(int timeout)
{
this.timeOut = timeout;
}
//...
}
I would like this Bean to be spring managed, so that I can use Spring AOP later.
<bean id="myBean" class="A" singleton="false">
</bean>
However my bean needs timeout to be passed as a dynamic value – is there a way to create a spring managed bean with dynamic value being injedcted in the constructor?
BeanFactoryhas agetBean(String name, Object... args)method which, according to the javadoc, allows you to specify constructor arguments which are used to override the bean definition’s own arguments. So you could put a default value in the beans file, and then specify the “real” runtime values when required, e.g.and then:
I haven’t tried this myself, but it should work.
P.S.
scope="prototype"is now preferable tosingleton="false", which is deprecated syntax – it’s more explicit, but does the same thing.