Results 1 to 3 of 3

Thread: How to set multiple parameters as setter injection?

  1. #1
    Join Date
    Oct 2010
    Posts
    4

    Question How to set multiple parameters as setter injection?

    Hello,

    I have a use case where I have a setter-method with 2 parameters. Is there a way to let Spring inject two parameters for this setter-method? I have read, that this is possible with constructors, but haven't found anything for setter-methods.

    thanks for your help!

    greets,
    Oli

  2. #2
    Join Date
    Oct 2009
    Location
    Sofia, Bulgaria
    Posts
    20

    Default

    Hi Oli,

    I'm not sure whether it is possible at all. But having a setter method with two parameters contradicts to the JavaBeans specification. And the idea of the spring container is to treat your class exactly as a java bean.

    So either break your setter method to two methods or create a composite class that contains the two attributes that you need to pass.

    Cheers,
    Ivan

  3. #3
    Join Date
    Oct 2010
    Posts
    4

    Default

    That's true about the Java bean specification. Therefore I will implement something like a wrapper class, as you mentioned before.

    Thanks for the tipp!

Tags for this Thread

Posting Permissions

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