Announcement Announcement Module
Collapse
No announcement yet.
how to pass a parameter to constructor of a Bean when getting it from context? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to pass a parameter to constructor of a Bean when getting it from context?

    Hi,

    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?

    Thanks.

  • #2
    Hi,

    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.
    G.

    Comment

    Working...
    X