Dec 6th, 2010, 03:35 PM
how to pass a parameter to constructor of a Bean when getting it from context?
I have a class called Utils which is start of my application. In this class I am getting UtilHelper from the spring context using getBean method.
I have a variable in the Utils class which I want to pass it to UtilHelper class constructor, is that possible?
Dec 7th, 2010, 05:24 AM
What you are getting from the context using "getBean(...)" is an instance of the constructor. And at the moment you are retrieving the constructor values are already set. So you could maybe try with setter methods that are declared in the same class where the constructor is!
Anyway, I think it is the result of a bad design to set the constructor values via injection (ApplicationContext) and then give parameters in the java Code. Why dont you give all parameters in the configuration file??
Maybe you should show us a bit of your code.