Spring retry(二)- 源码解析-启动装配篇 @EnableRetry

上一篇文章,我们快速介绍了下spring-retry的使用技巧,本篇我们将会剖析源码去学习

一、 EnableRetry注解

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@EnableAspectJAutoProxy(proxyTargetClass = false)
@Import(RetryConfiguration.class)
@Documented
public @interface EnableRetry {
   

   /**
    * Indicate whether subclass-based (CGLIB) proxies are to be created as opposed to
    * standard Java interface-based proxies. The default is {@code false}.
    * @return whether to proxy or not to proxy the class
    */
   @AliasFor(annotation = EnableAspectJAutoProxy.class)
   boolean proxyTargetClass() default false;

   /**
    * Indicate the order in which the {@link RetryConfiguration} AOP <b>advice</b> should
    * be applied.
    * <p>
    * The default is {@code Ordered.LOWEST_PRECEDENCE - 1} in order to make sure the
    * advice is applied before other advices with {@link Ordered#LOWEST_PRECEDENCE} order
    * (e.g. an advice responsible for {@code @Transactional} behavior).
    */
   int order() default Ordered.LOWEST_PRECEDENCE - 1;

}

英文翻译我就不再解释了,上面说的很清楚;这里重点提一下@Import(RetryConfiguration.class)这个注解,表明了@EnableRetry注解的启动配置类是RetryConfiguration, 通过@Import注解来注入对应的配置类,这样的做法同样可见于@EnableAsync/@EnableScheduling等注解上; 看到这里,如何定义一个Enable配置注解是不是会了呢~

二、 RetryConfiguration如何构建 ponintCut和advisor

@SuppressWarnings("serial")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Component
public class RetryConfiguration extends AbstractPointcutAdvisor
      implements IntroductionAdvisor, BeanFactoryAware, InitializingBean, SmartInitializingSingleton, ImportAware {
   

    //在这里构建了ponintCut和advice
    @Override
    public void afterPropertiesSet() throws Exception {
   
       this.retryContextCache = findBean(RetryContextCache.class);
       this.methodArgumentsKeyGenerator = findBean(MethodArgumentsKeyGenerator.class);
       this.newMethodArgumentsIdentifier = findBean(NewMethod
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值