Skip to content

Kotlin extension for GenericApplicationContext with registerBean(KClass) variants [SPR-15048] #19614

Closed

Description

@spring-projects-issues

Juergen Hoeller opened SPR-15048 and commented

Following up on the GenericApplicationContext revision in #19398, let's consider creating a dedicated GenericKotlinApplicationContext subclass with registerBean(KClass) variants or Kotlin extensions to GenericApplicationContext itself with the same method variations.


Issue Links:

Referenced from: commits ff675f5

Activity

  1. spring-projects-issues commented on Dec 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Juergen Hoeller Instead of creating a dedicated GenericKotlinApplicationContext, what about providing the same kind of extensions I created here builtin with Spring JARs to provide these additional methods?

    From a Kotlin developer POV, that would allow to write exactly the same code, but without requiring us to create a parallel class hierarchy for Kotlin additional methods. And extensions are really widely used in Kotlin, they are not perceived as less natural or second class support. They are statically resolved, you have to import them to have the additional methods, but the IDE make a very good job to auto import them when needed.

    2 additional avantages I can see: this will make these additional methods available in every class extending GenericApplicationContext like AnnotationConfigApplicationContext and that will allow us to provide extension like KClass variants in many other places (WebClient, RestTemplate, functional web framework) in a consistent way without having to create Kotlin specific wrappers.

  2. spring-projects-issues commented on Dec 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Good point, and as long as they are aligned with the existing registerBean methods on GenericApplicationContext, they are not sneaking a new concept into that existing class either... rather just variants of existing methods with KClass arguments. So yes, sounds good to me; let's try to ship those Kotlin extensions in M4 then!

  3. spring-projects-issues commented on Dec 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Ok perfect :-)

    The tricky part will be to disable conditionally the kotlin compiler to avoid breaking JDK9 builds since https://youtrack.jetbrains.com/issue/KT-14988 is not fixed yet on Kotlin side. Do you think this is something doable? I will have a look myself but I just want to raise the point in case you have some thought about the feasibility.

  4. spring-projects-issues commented on Dec 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    It looks like conditional apply statements for a plugin actually work:

    if (!JavaVersion.current().java9Compatible) {
    	apply plugin: "kotlin"
    }
    

    I've just tried it with our test sources but I guess it'll also work for regular resources.

  5. spring-projects-issues commented on Dec 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Awesome, thanks for your help. I will work on this Monday then.

  6. spring-projects-issues commented on Dec 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Implemented via this commit.

    I used Kotlin extensions nested in an object container to provide a scalable way to organize such extensions without risking naming conflicts.

    IDEA currently fails to suggest automatically these extensions due some limitation on extension detection, so I have created KT-15440 to ask some improvements.

    Mix-IT website has been updated to use directly these extensions instead of its own.

    Juergen Hoeller If you are ok with that, I suggest adding for M4 similar extensions for Web functional client and server (see #19620) in order to provide a complete out of the box support for such functional Web application use case.

  7. spring-projects-issues commented on Dec 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Sounds great! Let's make the Kotlin story as complete as we can for M4 and blog about it in January already.

  8. added
    type: enhancement
    in: core
    on Jan 11, 2019
  9. added this to the 5.0 M4 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