码迷,mamicode.com
首页 > 编程语言 > 详细

spring --自定义注解(配合@Aspect)

时间:2018-05-31 13:19:43      阅读:425      评论:0      收藏:0      [点我收藏+]

标签:als   dex   ann   span   cut   exist   join   code   err   

1:首先,声明自定义注解

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface DtTransactional {
   
   /*
    * Whether need to rollback
    */
   public boolean includeLocalTransaction() default true;
   
   public boolean confirmMethodExist() default true;
   
   /*
    * Allow [confirmMethod] is null if [confirmMethodExist] is false
    */
    public String confirmMethod() default "";

    public String cancelMethod();
    
}

2:定义切面处理类

@Aspect
@Component
@Slf4j
public class DistributedTransactionAspect implements Ordered{
    
    @Autowired
    private DistributedTransactionInterceptor distributedTransactionInterceptor;

    @Pointcut("@annotation(com.sysware.cloud.commons.dts.annotation.DtTransactional)")
    public void distributedTransactionService() {

    }

    @Around("distributedTransactionService()")
    public Object interceptDtTransactionalMethod(ProceedingJoinPoint pjp) throws Throwable {
        log.debug("interface-ITransactionRunning-start---->");
        Object obj =  distributedTransactionInterceptor.interceptDtTransactionalMethod(pjp);
        log.debug("interface-ITransactionRunning-end---->");
        return obj;
    }

    @Override
    public int getOrder() {
        return HIGHEST_PRECEDENCE;
    }

}

定义切面处理类关键点:

  1.   类用@Aspect

spring --自定义注解(配合@Aspect)

标签:als   dex   ann   span   cut   exist   join   code   err   

原文地址:https://www.cnblogs.com/wenq001/p/9116120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!