Results 1 to 2 of 2

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

  1. #1
    Join Date
    Dec 2005
    Posts
    11

    Default 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. #2
    Join Date
    Nov 2010
    Posts
    11

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •