通知的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. 微软中国发布“IE8浏览器性能解密”,为金山网盾辟谣
  2. hadoop运维必备命令
  3. 探索Julia(part12)--函数组合及管道
  4. python中csv文件通过什么表示字符_python_写入csv文件时候无法进行原样写入(写入字符串中出现逗号,时候,csv文件自动分成两个单元格)...
  5. 怎么成为日上会员直邮_18个日上直邮问题汇总,可以参考一下哦
  6. 京东下拉词框推广是什么?
  7. android 拉伸图片
  8. A Game USACO 3.3 (DP阵亡)
  9. PC机中各类存储器的逻辑连接情况
  10. jdk unsafe类源码解析
  11. 关于Java html table表格转excel
  12. VUE配置本地代理服务器
  13. 山东大学网络考试的计算机试题及答案,专科 计算机基础 山东大学网络教育考试模拟题及答案.doc...
  14. 关于si4438以往犯的一些错误
  15. android dp转px的公式_dp与px的转换对照表
  16. imresize函数进行图像缩放及利用imrotate进行图像旋转
  17. 使用python把普通图片生成ico图标
  18. mysql端口establish_sqlserver提示The Network Adapter could not establish the con
  19. html文本框自动宽度,input文本框宽度自适应
  20. Mac一些基本常用快捷键的使用

热门文章

  1. 064:vue+openlayers根据坐标来显示点、线段、圆形、多边形(代码示例)
  2. python抢火车票 短信通知
  3. mac 电池不在充电
  4. .net core依赖注入
  5. NSN HLR simulator for provisioning in expect
  6. 无法识别 移动固态硬盘_M.2固态硬盘不能识别怎么办 Bios开启CSM识别M.2固态硬盘方法...
  7. 怎样将列表、数组中的每个数都保留两位有效数字
  8. 小白也可以学会小爱同学语言控制灯
  9. 数据可视化-----标签云的实现
  10. codevs——T1219 骑士游历