Skip to content

GenericApplicationContext.registerBean should support non-default constructors [SPR-17292] #21825

Closed

Description

@spring-projects-issues

Juergen Hoeller opened SPR-17292 and commented

While AnnotationConfigApplicationContext.registerBean supports @Autowired resolution on constructors in case of no instance supplier given, the original method on GenericApplicationContext performs default instantiation only. Making GenericApplicationContext.registerBean smarter in detecting a Kotlin primary constructor or simple non-default public constructor scenarios makes it aligned with AnnotationConfigApplicationContext and more useful in general, in particular for Kotlin DSLs.


Issue Links:

Referenced from: commits 47d6e91, d3c0855

Activity

  1. spring-projects-issues commented on Sep 19, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Since full AUTOWIRE_CONSTRUCTOR exhaustively looks at all constructors (public, private, whatever), it does not seem like an ideal candidate here. Instead, a new "preferred constructors" mechanism allows registerBean to suggest the Kotlin primary constructor and standard public constructors to be evaluated for autowiring before falling back to default instantiation. This covers the intended use cases and is largely aligned with the constructor determination algorithm for model attribute processing.

  2. spring-projects-issues commented on Sep 19, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Sébastien Deleuze, this should cover your intended use case in the Kotlin DSL now, with no need for a custom post-processor anymore.

  3. spring-projects-issues commented on Sep 19, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Thanks, I have updated the Kotlin DSL accordingly.

  4. added
    type: enhancement
    in: core
    on Jan 11, 2019
  5. added this to the 5.1 GA milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions