Announcement Announcement Module
Collapse
No announcement yet.
How to set multiple parameters as setter injection? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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!

      Comment

      Working...
      X