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(); }

自定义注解定义的属性方法,如果没有 default “” ,则使用该注解时该属性为必填 ;

2:定义切面处理类

@Aspect
@Component
@Slf4j
public class DistributedTransactionAspect{ @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;
}
}

定义切面处理类关键点:

  1:类上面用@Aspect 注解修饰 。

2:定义切点,用@Pointcut("@annotation(com.sysware.cloud.commons.dts.annotation.DtTransactional)") 注解定义切点,

  表示扫描所有用@DtTransactional注解标识的方法 。

3:用@Around @Before @After 注解标识,标识拦截方法的时机 ;@Before是在所拦截方法执行之前执行一段逻辑。

  @After 是在所拦截方法执行之后执行一段逻辑。@Around是可以同时在所拦截方法的前后执行一段逻辑。

4:参数ProceedingJoinPoint pjp 通过pjp 可以获取注解信息,注解的参数,方法名,方法参数类型,方法参数等数据,然后对数据做一些统一处理。

spring --解析自定义注解SpringAOP(配合@Aspect)的更多相关文章

  1. 利用Spring AOP自定义注解解决日志和签名校验

    转载:http://www.cnblogs.com/shipengzhi/articles/2716004.html 一.需解决的问题 部分API有签名参数(signature),Passport首先 ...

  2. (转)利用Spring AOP自定义注解解决日志和签名校验

    一.需解决的问题 部分API有签名参数(signature),Passport首先对签名进行校验,校验通过才会执行实现方法. 第一种实现方式(Origin):在需要签名校验的接口里写校验的代码,例如: ...

  3. spring AOP自定义注解方式实现日志管理

    今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...

  4. spring AOP自定义注解 实现日志管理

    今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...

  5. 使用Spring Aop自定义注解实现自动记录日志

    百度加自己琢磨,以下亲测有效,所以写下来记录,也方便自己回顾浏览加深印象之类,有什么问题可以评论一起解决,不完整之处也请大佬指正,一起进步哈哈(1)首先配置文件: <!-- 声明自动为sprin ...

  6. JAVA自定义注解SpringAOP

    原文:https://my.oschina.net/wangnian/blog/801348 前言:Annotation(注解)是JDK5.0及以后版本引入的,它的作用就是负责注解其他注解.现在开发过 ...

  7. Spring aop+自定义注解统一记录用户行为日志

    写在前面 本文不涉及过多的Spring aop基本概念以及基本用法介绍,以实际场景使用为主. 场景 我们通常有这样一个需求:打印后台接口请求的具体参数,打印接口请求的最终响应结果,以及记录哪个用户在什 ...

  8. Spring Cache 自定义注解

    1.在使用spring cache注解如cacheable.cacheevict.cacheput过程中有一些问题: 比如,我们在查到一个list后,可以将list缓存到一个键对应的区域里:当新增.修 ...

  9. 结合spring 实现自定义注解

    注解类 import java.lang.annotation.*; /** * Created by Administrator on 2016/6/28. */ //ElementType.MET ...

随机推荐

  1. iOS 性能监测

    给些链接: http://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ%3D%3D&idx=1&mid=207890859&scene=23& ...

  2. 关于MVC 上传文件

    前台代码如下 @{ Layout = null; } <!DOCTYPE html> <html> <head> <title>Index</ti ...

  3. python下载网页上公开数据集

    URL很简单,数据集分散开在一个URL页面上,单个用手下载很慢,这样可以用python辅助下载: 问题:很多国外的数据集,收到网络波动的影响很大,最好可以添加一个如果失败就继续请求的逻辑,这里还没有实 ...

  4. Matrix_QP(A_2SeqSum)

    hdu_4686 题目大意:给出an,bn的递推,求ai*bi(i=0,1,--n-1)的和(an=a(n-1)*Ax+Ay, bn=b(n-1)*Bx+By, a0=A0, b0=B0, Ax,Bx ...

  5. c# iText 生成PDF 有文字,图片,表格,文字样式,对齐方式,页眉页脚,等等等,

    #region 下载说明书PDF protected void lbtnDownPDF_Click(object sender, EventArgs e) { int pid = ConvertHel ...

  6. springMVC数据回显

    1.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  7. 梅森素数应用 nefu 120

    梅森素数 定义: if m是一个正整数 and 2^m-1是一个素数 then m是素数 if m是一个正整数 and m是一个素数 then M(m)=2^m-1被称为第m个梅森数 if p是一个素 ...

  8. 第一个版本库 Repository

    Git安装 Windows系统 Git 为 Windows 系统提供了简易的 .exe 安装包, 直接下载并安装就可以了(点这里->):https://git-scm.com/download/ ...

  9. UVa 11396 爪分解(二分图判定)

    https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...

  10. HtmlAgilityPach基本使用方法

    //过滤html标签 static void InnerText() { HtmlWeb htmlWeb = new HtmlWeb(); HtmlDocument doc = htmlWeb.Loa ...