我定义了一个接口
public interface MyInterface {
default void setOrder(int a){ }
default int getOrder(){return 123;}
}
实施和实现
public class MyInterfaceImpl implements MyInterface {}
在我的Spring配置文件中,我定义了以下bean:
<bean id="a" class="my.package.MyInterfaceImpl">
<property name="order" value="999"/>
</bean>
当我创建Spring上下文时,出现以下错误:
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?
我正在使用版本为4.1.6.RELEASE的Spring。所以我的问题是为什么无法执行接口MyInterface中默认方法setOrder?似乎Spring完全忽略了这些方法。
<property name="order" value="999"/>
更改为<property name="order" value="123"/>
,因为您的默认 getter 返回的是123
而不是999
。 - Tobias Kloss