问题
I have defined interface
public interface MyInterface {
default void setOrder(int a){ }
default int getOrder(){return 123;}
}
and implementation
public class MyInterfaceImpl implements MyInterface {}
In my spring configuration file I have defined following bean:
<bean id="a" class="my.package.MyInterfaceImpl">
<property name="order" value="999"/>
</bean>
When I create spring context I got following error:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'order' of bean class [my.package.MyInterfaceImpl]: Bean property 'order' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
I am using spring in version 4.1.6.RELEASE. So my question is why it is not possible to execute method setOrder which is default method from interface MyInterface? It seems that spring completely ignore such methods.
回答1:
Handling of default methods in interfaces will come with Spring 4.2, so until then either use the release candidates or milestones or don't use default methods with Spring (https://jira.spring.io/browse/SPR-12822 or https://jira.spring.io/browse/SPR-10919)
回答2:
This issue is still present in the Spring 4.2.5.RELEASE
I have thrown together an example that showcases it on Github here: https://github.com/cjbooms/spring-default-methods
And logged a ticket with Spring here: https://jira.spring.io/browse/SPR-14198
来源:https://stackoverflow.com/questions/30477367/spring-4-cannot-execute-java-8-default-methods