Results 1 to 3 of 3

Thread: constructor autowiring

  1. #1
    Join Date
    Oct 2008
    Posts
    2

    Default 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. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    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. #3
    Join Date
    Oct 2008
    Posts
    2

    Default

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

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
  •