Spring AOP 原型范围的方面乱序触发

Spring AOP Prototype-scoped Aspects are Firing out-of-order

我正在使用一组 Spring AOP 方面(主要来自我的库 here)。我发现当方面 bean 的范围是 "prototype"。如果我删除 XML 中的 'scope="prototype"' 或 JavaConfig 中的 @Scope("prototype"),排序是正确的,但是当范围是原型时,排序不正确工作 - 这些方面显然以随机顺序触发。这些方面实现了 Ordered 接口。

Bean 定义遵循模式 (JavaConfig):

@Bean
@Scope("prototype")
public CircuitBreakerAspect circuitBreakerAspect()
{
    CircuitBreakerAspect aspect = new CircuitBreakerAspect();
    aspect.setGraphiteClient(graphiteClient);
    aspect.setOrder(100);
    return aspect;
}

我需要方面是原型范围,因为其中一些(例如,RetryInterceptor)是有状态的(维护失败操作的计数,导出到 JMX)。如果我删除原型作用域,排序工作正常,但相同的单例方面实例用于所有建议的 bean 实例!

我在 Spring Boot 1.4.1 和 Java 8.

我怎样才能让原型方面正确排序?

我认为 prototype 范围不受方面的支持,或者更有可能它没有意义。 11.2.6 Aspect instantiation models 的文档特别提到了这一点:

By default there will be a single instance of each aspect within the application context.

要修改此行为,Spring AOP 支持 AspectJ perthispertarget 实例化模型。也许它们对你有用。

这似乎是 Spring 中的错误。如果我将 @Order 注释添加到方面,它们就会正确排序。我已经用 Spring 提交了一个错误。 https://jira.spring.io/browse/SPR-14959