Spring 4 无法执行 Java 8 默认方法

标签 spring java-8 spring-4

我已经定义了接口(interface)

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。所以我的问题是为什么不能从接口(interface) MyInterface 执行默认方法 setOrder 方法?似乎spring完全忽略了这些方法。

最佳答案

Spring 4.2 将处理接口(interface)中的默认方法,因此在此之前要么使用候选版本或里程碑,要么不要使用 Spring 的默认方法( https://jira.spring.io/browse/SPR-12822https://jira.spring.io/browse/SPR-10919 )

关于Spring 4 无法执行 Java 8 默认方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30477367/

相关文章:

java - 如何在hibernate中更新父表的主键,从而自动更新子表的外键?

java - Spring MVC - Ehcache最佳实践

java - 如何在Spring Security中为两个不同的URL指定两个不同的登录表单?

Java构造函数引用赋值 VS 新建对象赋值

java - 如何将 Spring 4 与 Apache Tiles 3 集成?

java - Spring 4 迁移 : OutOfMemoryError: PermGen Space

java - Spring MVC Controller 代码 : getOutputStream() has already been called for this response

java - 在 Java 8 中使用 Group By 和属性

java - 使用 lambda 和流按值对 map 进行排序

caching - 使用 Spring Boot 1.5 设置 Ehcache 3 时出错