Spring 4无法执行Java 8默认方法 [英] Spring 4 cannot execute Java 8 default methods

查看:188
本文介绍了Spring 4无法执行Java 8默认方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经定义了接口

public interface MyInterface {
  default void setOrder(int a){ }
  default int getOrder(){return 123;}
}

和实现

public class MyInterfaceImpl implements MyInterface {}

在我的spring配置文件中,我定义了以下bean:

In my spring configuration file I have defined following bean:

    <bean id="a" class="my.package.MyInterfaceImpl">
    <property name="order" value="999"/>
</bean>

当我创建spring上下文时出现以下错误:

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?

我在版本4.1.6.RELEASE中使用spring。所以我的问题是为什么不能从接口MyInterface执行默认方法setOrder?似乎spring完全忽略了这样的方法。

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.

推荐答案

接口中的默认方法的处理将随Spring 4.2一起提供,所以在此之前使用发布候选版本或里程碑或不使用Spring的默认方法( https://jira.spring.io/browse/ SPR-12822 https://jira.spring.io/browse/SPR-10919

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)

这篇关于Spring 4无法执行Java 8默认方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆