Announcement Announcement Module
No announcement yet.
constructor autowiring Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • constructor autowiring

    Using 2.5
    If I have an existing bean having constructors Bean(A), Bean(A, B), Bean (A, B, C), Bean (A, D) and A, B, C and D are all present in the context, which constructor will be used for wiring?
    When I tried this out, I didn't get any exceptions. Should there be any or Spring would randomly pick one of the constructors...

  • #2
    3.11.2. @Autowired:
    Only one annotated constructor per-class may be marked as required, but multiple non-required constructors can be annotated. In that case, each will be considered among the candidates and Spring will use the greediest constructor whose dependencies can be satisfied.


    • #3
      I am not using Annotations. I guess with XML the "greediest" rule applies.