Java 如何使用1.0.3版本的Spring retry启用Spring retry?

Java 如何使用1.0.3版本的Spring retry启用Spring retry?,java,spring,spring-aop,spring-annotations,spring-aspects,Java,Spring,Spring Aop,Spring Annotations,Spring Aspects,要启用Spring retry,可以在Java注释中启用retry:@EnableRetry in Configuration或在XML配置文件中指定retry: <context:annotation-config /> <aop:aspectj-autoproxy /> <bean class="org.springframework.retry.annotation.RetryConfiguration" /> 这两个规范都基于仅从版本1.1.2开

要启用Spring retry,可以在Java注释中启用retry:@EnableRetry in Configuration或在XML配置文件中指定retry:

<context:annotation-config />
<aop:aspectj-autoproxy />
<bean class="org.springframework.retry.annotation.RetryConfiguration" />

这两个规范都基于仅从版本1.1.2开始的…annotation.RetryConfiguration。如何在以前的版本中启用XML配置中的重试?由于兼容性问题,我无法使用1.1.2版。重试配置如下所示:

<aop:config>
    <aop:pointcut id="retrySave"
        expression="execution( * sfweb.service.webServiceOrders.WsOrderCreationServiceImpl.saveLedger(..))" />
    <aop:advisor pointcut-ref="retrySave" advice-ref="retryAdvice"
        order="-1" />
</aop:config>

<bean id="retryAdvice"
    class="org.springframework.retry.interceptor.RetryOperationsInterceptor">
</bean>

Spring Retry 1.0.3没有基于AspectJ的AOP支持。因此,方面样式重试将不适用于该版本。相反,可检索代码需要包装在
RetryCallback
的实例中。一般做法如下:

<aop:config>
    <aop:pointcut id="retrySave"
        expression="execution( * sfweb.service.webServiceOrders.WsOrderCreationServiceImpl.saveLedger(..))" />
    <aop:advisor pointcut-ref="retrySave" advice-ref="retryAdvice"
        order="-1" />
</aop:config>

<bean id="retryAdvice"
    class="org.springframework.retry.interceptor.RetryOperationsInterceptor">
</bean>
1.创建一个
RetryTemplate

2.将可检索代码包装在
RetryCallback中


除了发布的答案,我们还需要一个代码来传递可重试操作的参数。这可以在FailureProneOperation构造函数中完成:

public FailureProneOperation(OrderSkuLedger orderSkuLedger) {
    this.orderSkuLedger = orderSkuLedger;
}

因此,如果我有一个在类方法中调用的方法saveLedger,那么它应该安装在什么地方?
doWithRetry(…){saveLedger(…);}
。如何将参数传递给saveLedger(),您可以公开包装类
failureproneoption
上的属性,您可以在其上设置所有上下文数据。您在下面答案中的建议也将起作用。
retryTemplate.execute(new FailureProneOperation())
public FailureProneOperation(OrderSkuLedger orderSkuLedger) {
    this.orderSkuLedger = orderSkuLedger;
}