通知的5种类型:执行顺序:相同类型已配置顺序为准
1.before:<aop:before method="before" pointcut-ref="pt"/>
2.after:<aop:after method="after" pointcut-ref="pt"/> 
3.afterReturning:返回后加入,有异常不执行<aop:after-returning method="afterReturning" pointcut-ref="pt"/>
4.afterThrowing:有异常才会执行<aop:after-throwing method="afterThrowing" pointcut-ref="pt"/>
5.round:<aop:around method="round" pointcut-ref="pt"/>
用法最广泛,可替代before,after,调用目标方法
public void round(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("round before");
pjp.proceed();
System.out.println("round after");

}

代码实现:

1.目标对象:

    

public void save() {//int i = 1/0;System.out.println("save.....");}
}

    2.通知:

    

public class MyTarget2 {
public class MyAdvice2 {public void before() {System.out.println("before");}public void after() {System.out.println("after");}public void afterReturning() {System.out.println("afterReturning");}public void afterThrowing() {System.out.println("afterThrowing");}public void round(ProceedingJoinPoint pjp) throws Throwable {System.out.println("round before");pjp.proceed();System.out.println("round after");}
}

    3.xml文件:

<?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:util="http://www.springframework.org/schema/util"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--spring管理资源都是bean的形式  --><!-- 你的资源是那个类的对象 <bean class="类名" id="类名对应的唯一标识"></bean>--><!--配置aop,切入点与通知之间的关系   _切面 --><!--aop:config:配置aop  --><aop:config><aop:pointcut expression="execution(void com.array.aop.adviceType.MyTarget2.save())" id="pt"/><aop:aspect ref="myAdvice2"><!--配置aop的通知类别  aop:before method="" 通知类别的具体通知aop:before pointcut=""切入点<aop:before method="fn1" pointcut="执行到save方法时"/>--><!-- 在方法save的前面加入方法fn --><!-- <aop:before method="before" pointcut-ref="pt"/><aop:after method="after" pointcut-ref="pt"/> --><!-- <aop:after-returning method="afterReturning" pointcut-ref="pt"/> --><aop:around method="round" pointcut-ref="pt"/><aop:after-throwing method="afterThrowing" pointcut-ref="pt"/></aop:aspect></aop:config><!--/将目标对象与通知定义为bean  --><bean id="myAdvice2" class="com.array.aop.adviceType.MyAdvice2"></bean><bean id="myTarget2" class="com.array.aop.adviceType.MyTarget2"></bean>
</beans>

advice的五种类型相关推荐

  1. 在Oracle中CHAR,NCHAR,VARCHAR,VARCHAR2,NVARCHAR2这五种类型的区别

    [在Oracle中CHAR,NCHAR,VARCHAR,VARCHAR2,NVARCHAR2这五种类型的区别 ] 1.CHAR(size)和VARCHAR(size)的区别  CHAR为定长的字段,最 ...

  2. StatsD 五种类型数据发送形式拟测试

    statsd 五种类型数据发送形式拟测试 StatsD Metric Types Counting gorets:1|c This is a simple counter. Add 1 to the ...

  3. 做短视频可以选哪些领域?推荐五种类型短视频,选对方向很重要

    做短视频可以选哪些领域?推荐五种类型短视频,选对方向很重要 刚刚进入短视频行业的小伙伴们想必都在苦恼如何选择短视频领域,毕竟想要长久发展短视频的话,那么就必须要选对方向,按照选择好的方向一直走,才能够 ...

  4. 什么是通知?有哪五种类型的通知?

    通知是个在方法执行前或执行后要做的动作,实际上是程序执行时要通过SpringAOP框架触发的代码段. Spring切面可以应用五种类型的通知: a.before:前置通知,在一个方法执行前被调用. b ...

  5. 什么内容的短视频可以吸引粉丝?分享五种类型短视频,供你选择

    什么内容的短视频可以吸引粉丝?分享五种类型短视频,供你选择 短视频的制作其实并不难,主要难点还是在于短视频的内容选题.引流等.那么今天我们就一起来着重的了解一下看什么内容的短视频可以吸引粉丝,这里简单 ...

  6. linux下的文件可以分为哪五种类型,LINUX系统文件类型分类

    使用LINUX过程中,时常会对文件进行操作.但是linux中文件究竟有哪些分类呢?今天让我们大家来总结一下吧! 概述: linux文件可以分为五种类型,分别为:普通文件.目录.字符设备或块设备.套接口 ...

  7. Oracle 索引扫描的五种类型

    之前在讨论CBO和RBO的时候提到了索引扫描的几种类型. Oracle Optimizer CBO RBO http://blog.csdn.net/tianlesoftware/archive/20 ...

  8. 计算机控制系统的五种类型,计算机控制系统习题(1-5章

    <计算机控制系统习题(1-5章>由会员分享,可在线阅读,更多相关<计算机控制系统习题(1-5章(9页珍藏版)>请在人人文库网上搜索. 1.计算机控制系复习题(1-5章)第一章 ...

  9. 软文写作类型有哪些?总结这五种类型,让你轻松写出爆款文案

    软文应该是网络推广中最受欢迎的方法之一,因为软文推广的成本低,效果也比硬广告更持久,但是,软文推广也需要方法,一篇优质的软文能够让产品转化率更高,所以小编总结了下面五种容易出爆款的写作类型,让我们一起 ...

最新文章

  1. 关于sysobjects这个表
  2. python的源代码文件的扩展名是-python源文件后缀是什么
  3. 概率模型分子动力学模拟五元环吡咯C4H5N
  4. 第四范式携手工银科技 首批入驻雄安人工智能算法开放平台
  5. WPF自定义控件与样式(8)-ComboBox与自定义多选控件MultComboBox
  6. Analysis of Cloud Computing Architectures阅读笔记--提出了Screen虚拟化方法
  7. 产品经理没有做过成功的产品,该何去何从?
  8. html表头和左侧固定js,JS固定表头及固定左边列
  9. CAD工程图纸转jpg格式教程
  10. AndroidQ 锁屏密码验证流程之GateKeeper解析
  11. oracle 字段别名
  12. 一个操作系统的实现:BOOT
  13. 十进制与二进制之间转换详解
  14. 微信「搜一搜」功能简直就是宝藏功能,原来这么好用!
  15. element日历组件只显示月和日,把年份隐藏掉
  16. Tablespace for table ‘`xxx`.`xxx`‘ exists. Please DISCARD the tablespace
  17. Go语言头秃之路(五)
  18. “S“型曲线加减速在42步进电机的位置控制和速度控制中的交叉应用
  19. 中国象棋软件-引擎实现(三)着法生成
  20. 品味澳洲人民的“快乐人生”

热门文章

  1. 项目实战--用户消费数据分析
  2. 昆虫繁殖(继续理解递推和递归)
  3. Eureka的限流算法类RateLimiter源码解读
  4. 情绪激动的时候最好不要做决定
  5. 使用convert命令将pdf转成图片时遇到的一个问题
  6. C语言求二维数组鞍点
  7. windows10U盘启动
  8. Spring,Spring MVC及Spring Boot区别,你分清了吗
  9. 怎样降低微信h5棋牌游戏类app域名被微信拦截封杀屏蔽的几率
  10. The rollout of the Indian motorcycle brand continues apace