Skip to content

Java 8 default methods not detected as bean properties [SPR-14198] #18772

Closed

Description

@spring-projects-issues

Conor Gallagher opened SPR-14198 and commented

As the title suggests, Spring 4.2.5.RELEASE cannot inject into Java 8 default methods via xml context files.

I have thrown together a simple example on GitHub to demonstrate how this fails:

    void setSomeDate(LocalDate localDate);

    default void setSomeDateInDayMonthYear(String dayMonthYear) {
        setSomeDate(LocalDate.parse(dayMonthYear, DateTimeFormatter.ofPattern("dd/MM/yyyy")));
    }

An egregious workaround is to reference the default method from the implementation as follows:

@Override
public void setSomeDateInDayMonthYear(String dayMonthYear) {
    SomeInterface.super.setSomeDateInDayMonthYear(dayMonthYear);
}

Also referenced on SO:
http://stackoverflow.com/questions/30477367/spring-4-cannot-execute-java-8-default-methods


Affects: 4.2.5

Reference URL: https://github.com/cjbooms/spring-default-methods

Issue Links:

Referenced from: commits ce2f28d

Activity

  1. spring-projects-issues commented on Apr 27, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Unfortunately, even the JDK's own JavaBeans Introspector does not detect setters and getters as default methods. I've added some explicit code to our CachedIntrospectionResults, querying the introspector explicitly for each implemented interface and adding missing bean properties that way.

    This will be available in the upcoming 4.3.0.BUILD-SNAPSHOT and make it into 4.3 RC2.

  2. spring-projects-issues commented on Apr 27, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Conor Gallagher commented

    Great work, thank you.

  3. added
    type: enhancement
    in: core
    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