Introductions

types-matching 指定声明类

implement-interface 指定接口

default-impl 指定接口实现类,将成为生命类的父类

<aop:config><aop:aspect id="moocAspectAOP" ref="moocAspect">
<!--             <aop:pointcut expression="execution(* com.imooc.aop.schema.advice.biz.*Biz.*(..))" id="moocPiontcut"/> -->
<!--             <aop:before method="before" pointcut-ref="moocPiontcut"/> -->
<!--             <aop:after-returning method="afterReturning" pointcut-ref="moocPiontcut"/> -->
<!--             <aop:after-throwing method="afterThrowing" pointcut-ref="moocPiontcut"/> -->
<!--             <aop:after method="after" pointcut-ref="moocPiontcut"/> -->
<!--             <aop:around method="around" pointcut-ref="moocPiontcut"/> --><!--             <aop:around method="aroundInit" pointcut="execution(* com.imooc.aop.schema.advice.biz.AspectBiz.init(String, int))  -->
<!--                             and args(bizName, times)"/> --><aop:declare-parents types-matching="com.imooc.aop.schema.advice.biz.*(+)" implement-interface="com.imooc.aop.schema.advice.Fit"default-impl="com.imooc.aop.schema.advice.FitImpl"/></aop:aspect></aop:config>

aspect 只支持单例

advisors

InvokeService:

import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.stereotype.Service;@Service
public class InvokeService {public void invoke() {System.out.println("InvokeService ......");}public void invokeException() {throw new PessimisticLockingFailureException("");}}

ConcurrentOperationExecutor:

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.core.Ordered;
import org.springframework.dao.PessimisticLockingFailureException;public class ConcurrentOperationExecutor implements Ordered {private static final int DEFAULT_MAX_RETRIES = 2;private int maxRetries = DEFAULT_MAX_RETRIES;private int order = 1;public void setMaxRetries(int maxRetries) {this.maxRetries = maxRetries;}public int getOrder() {return this.order;}public void setOrder(int order) {this.order = order;}public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {int numAttempts = 0;PessimisticLockingFailureException lockFailureException;do {numAttempts++;System.out.println("Try times : " + numAttempts);try {return pjp.proceed();} catch (PessimisticLockingFailureException ex) {lockFailureException = ex;}} while (numAttempts <= this.maxRetries);System.out.println("Try error : " + numAttempts);throw lockFailureException;}
}

Test:

@Testpublic void testSave() {InvokeService service = super.getBean("invokeService");service.invoke();System.out.println();service.invokeException();}

配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><context:component-scan base-package="com.imooc.aop.schema"></context:component-scan><aop:config><aop:aspect id="concurrentOperationRetry" ref="concurrentOperationExecutor"><aop:pointcut id="idempotentOperation"expression="execution(* com.imooc.aop.schema.advisors.service.*.*(..)) " />
<!--                 expression="execution(* com.imooc.aop.schema.service.*.*(..)) and -->
<!--                                 @annotation(com.imooc.aop.schema.Idempotent)" /> --><aop:around pointcut-ref="idempotentOperation" method="doConcurrentOperation" /></aop:aspect></aop:config><bean id="concurrentOperationExecutor" class="com.imooc.aop.schema.advisors.ConcurrentOperationExecutor"><property name="maxRetries" value="3" /><property name="order" value="100" /></bean></beans>

结果:

Spring_AOP代码修改_Introductions Advisors相关推荐

  1. TVM yolov3优化代码修改(编译运行OK)

    TVM yolov3优化代码修改(编译运行OK) yolov3_quantize_sample.py 附https://github.com/makihiro/tvm_yolov3_sample代码: ...

  2. python 批量下载 代码_Python + Selenium +Chrome 批量下载网页代码修改

    Python + Selenium +Chrome 批量下载网页代码修改 主要修改以下代码可以调用 本地的 user-agent.txt 和 cookie.txt 来达到在登陆状态下 批量打开并下载网 ...

  3. master-worker常驻型程序代码修改哪些需要重启master或者worker

    之前在yii的项目里用redis作为消息队列,现在很多任务需要延迟需求,于是把之前redis的消息队列替换成了rabbitmq 于是使用yii的yii2-queue这个组件 但是由于提供的yii qu ...

  4. 低版本IE浏览器不支持前端代码修改属性remove()的解决办法

    今天在工作中碰到了低版本IE浏览器不支持对象属性移除(remove)和添加(add)的方法,请教了同事结合在网上找到的资源最后写了这一段代码,完美的解决了一个前端基础问题,在此记录一下,希望可以帮助到 ...

  5. Asp.net使用代码修改配置文件的节点值

    使用代码修改配置文件的方法: 1.打开配置文件写入的权限 2.先按节点名称长到要修改的节点,然后删除,紧接着将有新值的节点添加回去 3.关闭配置文件写入的权限 修改Appsetting节点的值,修改其 ...

  6. python webdriver save_Python + Selenium +Chrome 批量下载网页代码修改【新手必学】

    Python + Selenium +Chrome 批量下载网页代码修改 主要修改以下代码可以调用 本地的 user-agent.txt 和 cookie.txt 来达到在登陆状态下 批量打开并下载网 ...

  7. 【Java】《面向对象程序设计——Java语言》Castle代码修改整理

    前言 最近闲来无事刷刷MOOC,找到以前看的浙大翁凯老师的<面向对象程序设计--Java语言>课程,重新过一遍仍觉受益颇深. 其中有一个Castle的例子,思路很Nice但代码很烂,翁凯老 ...

  8. qt添加菜单纯代码_开始玩qt,使用代码修改设计模式生成的菜单

    之前制作菜单时,不是纯代码便是用设计模式 直接图形化完成. 今天我就是想用代码修改已经存在的菜单项,如果是用代码生成的可以直接调用指针完成: 但通过设计模式完成的没有暴露指针给我,至少我没发现. 在几 ...

  9. Unity 代码修改宏名并一键打包

    Unity 代码修改宏名并一键打包 Unity3d 项目开发切换平台与发布版本时,不同的平台,不同的版本,可能会有不同的实现方式,这样就需要宏去控制调用,执行需要在该平台的逻辑操作.其中Unity内部 ...

  10. U3d 代码修改图片的尺寸

    同个代码修改图片尺寸.代码如下: public static Texture2D CreateResizeTexture(Texture2D tex, int width, int height, T ...

最新文章

  1. mesos安装,webui显示不正常
  2. Android异步编程
  3. 12 个提高JavaScript编码效率的 NPM 技巧
  4. (caffe入门)windows caffe 之 mnist 训练
  5. WEB数据挖掘(十)——Aperture数据抽取(6):在Aperture中使用RDF2Go
  6. nanopi制作个人服务器,NanoPi K2 服务器系统镜像
  7. c语言if大括号的作用,c语言if语句 用法是什么
  8. 吊打何同学?猛肝24小时,用6000元成本打造 AirDesk!
  9. Snapper转换器的捕捉类型
  10. html站点是啥意思,html啥意思
  11. 解决缺少API-MS-WIN-CORE-SYNCH-L1-1-0.DLL等一系列DLL的问题
  12. 第六章_编写定制标签
  13. Apache文件解析漏洞
  14. 用java定义三维空间的点
  15. HTML进阶- 4.6 补充一些不常用的元素
  16. Java中如何使用转义转义字符?
  17. PatterNodes for Mac(创建图形矢量模式工具)
  18. 数据预处理第6讲:正态变换
  19. 古堡算式_经典的全排列问题(福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式: ABCDE * ? = EDCBA 他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!” 华生:“我猜也)
  20. WICC 2021最新议程曝光 边缘计算将迎来突破性的科研分享

热门文章

  1. LOMO Effect预览界面没有立即完全隐藏
  2. 面试:Android应用的崩溃率
  3. 【OpenGL】室内3D弹球
  4. 程序员如何不加班?—— 时间管理篇
  5. 金之塔用 Python 获取日内分时均价,每分钟日成交量和每时刻结算价,及交叉作用曲线延伸
  6. C++ -Pointer指针总结(一)
  7. 360无线路由器dns服务器,路由器的首选dns服务器怎么填
  8. 北航大学计算机学院新媒体艺术系,本科优秀毕业论文参考-北航新媒体与艺术学院-北京航空航天大学.doc...
  9. 北京航空航天大学计算机学院保研,北京航空航天大学计算机学院(专业学位)计算机技术保研...
  10. 1和4互素吗_互素是什么意思判别方法,1和2互素,互素