Spring的通知(Advice)
Spring提供了5种Advice类型:
Interception Around:JointPoint前后调用
Before:JointPoint前调用
After Returning:JointPoint后调用
Throw:JoinPoint抛出异常时调用
Introduction:JointPoint调用完毕后调用
Interception Around通知
Interception Around通知会在JoinPoint的前后执行。实现此通知的类需要实现接口MethodInterceptor,示例代码如下:
public class LogInterceptor implements MethodInterceptor{
public Object invoke(MethodInvocation invocation invocation) throws Throwable{
System.out.println("开始审核数据...");
Object rval = invocation.proceed();
System.out.println("审核数据结束...");
return rval;
}
}
Before通知
只在JointPoint前执行,实现Before通知的类需要实现接口MethodBeforeAdvice,示例带入如下:
1 public class LogBeforeAdvice implements MethodBeforeAdvice{
2 public void before(Method m,Object[] args,Object target) throw Throwable{
3 System.out.println("开始审核数据...");
4 }
5 }
After Returning通知
只在JointPoint之后执行,实现After Returning通知的类需要实现接口AfterReturningAdvice,示例代码如下:
public class LogAfterAdvice implements AfterReturningAdvice{
public void afterReturning(Method m,Object[] args,Object target) throws Throwable{
System.out.println(“审核数据结束...”);
}
}
Throw通知
只在JointPoint抛出异常时执行,实现Throw通知的类需要实现接口ThrowsAdvice,示例代码如下:
public class LogThrowAdvice implements ThrowsAdvice{
public void afterThrowing(RemoteException ex) throws Throwable{
System.out.println("审核数据异常,请检查..."+ex);
}
}
Introduction通知
只在JointPoint调用完毕后执行,实现Introduction通知的类需要实现接口IntroductionAdvisor和接口IntroductionInterceptor
Spring的通知(Advice)的更多相关文章
- Spring学习(十五)----- Spring AOP通知实例 – Advice
Spring AOP(面向方面编程)框架,用于在模块化方面的横切关注点.简单得说,它只是一个拦截器拦截一些过程,例如,当一个方法执行,Spring AOP 可以劫持一个执行的方法,在方法执行之前或之后 ...
- Spring AOP通知实例 – Advice
Spring AOP(面向方面编程)框架,用于在模块化方面的横切关注点.简单得说,它只是一个拦截器拦截一些过程,例如,当一个方法执行,Spring AOP 可以劫持一个执行的方法,在方法执行之前或之后 ...
- 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-通知(Advice)API
本文翻译自Spring.NET官方文档Version 1.3.2. 受限于个人知识水平,有些地方翻译可能不准确,但是我还是希望我的这些微薄的努力能为他人提供帮助. 侵删. 让我们看看 Spring.N ...
- Spring笔记07(Spring AOP的通知advice和顾问advisor)
1.Spring AOP的通知advice 01.接口代码: package cn.pb.dao; public interface UserDao { //主业务 String add(); //主 ...
- SpringAOP 通知(advice)
@Aspect @Order(1) public class AopOne { /** * 目标方法执行之前 * @param joinPoint */ @Before("executi ...
- Spring系列26:Spring AOP 通知与顺序详解
本文内容 如何声明通知 如何传递参数到通知方法中 多种通知多个切面的通知顺序 多个切面通知的顺序源码分析与图解 声明通知 Spring中有5种通知,通过对应的注解来声明: @BeforeBefore ...
- spring事件通知机制详解
优势 解耦 对同一种事件有多种处理方式 不干扰主线(main line) 起源 要讲spring的事件通知机制,就要先了解一下spring中的这些接口和抽象类: ApplicationEventPub ...
- Spring的通知类型,切入表达式写法
转载自 https://www.cnblogs.com/ltfxy/p/9882697.html Spring中通知类型: 前置通知:目标方法执行之前进行操作,可以获得切入点信息 后置通知: 目标方 ...
- Spring横切面(advice),增强(advisor),切入点(PointCut)(转)
Spring横切面(advice),增强(advisor),切入点(PointCut)的一点理解: 1.Spring管理事务有2种,其中一种是HibernateTransactionManager管理 ...
- 011-Spring aop 002-核心说明-切点PointCut、通知Advice、切面Advisor
一.概述 切点Pointcut,切点代表了一个关于目标函数的过滤规则,后续的通知是基于切点来跟目标函数关联起来的. 然后要围绕该切点定义一系列的通知Advice,如@Before.@After.@Af ...
随机推荐
- Ubuntu下安装MySQL-python教程
http://blog.csdn.net/liushuaikobe/article/details/8586224 写得非常的好,也很详细. 有密码:mysql -u root -p 无密码:mysq ...
- CDR VBA将字母改为大写
ActiveShape.Text.FontProperties.Uppercase = cdrSmallCapsFontCase
- C# DataSet装换为泛型集合
1.DataSet装换为泛型集合(注意T实体的属性其字段类型与dataset字段类型一一对应) #region DataSet装换为泛型集合 /// <summary> /// 利用反射和 ...
- python升级
一开始有这个需求,是因为用 YaH3C 替代 iNode 进行校园网认证时,一直编译错误,提示找不到 Python 的某个模块,百度了一下,此模块是在 Python2.7 以上才有的,但是系统的自带的 ...
- mac 给某个目录添加权限
1 cd 到这个目录的上一层目录 2 sudo chmod -R 777 3 输入密码 4 完成
- 一个特殊情形的Mittag-Leffler分解
Mittag-Leffler分解定理的证明有多种,比如可以利用一维$\overline{\partial}$的解来构造相应的函数,还可以利用极点主部的Taylor多项式来进行修正使得$\sum(g_{ ...
- Android语录
1. application对象的生命周期是整个程序中最长的,它的生命周期就等于这个程序的生命周期.因为它是全局的单例的,所以在不同的Activity,Service中获得的对象都是同一个对象.因此在 ...
- windows
1.拷贝远程文件 net use \\10.130.80.62\ipc$ 密码 /user:用户名 xcopy "\\10.130.80.62\G$\yt\apache-tomcat-7.0 ...
- Oracle执行计划详解
Oracle执行计划详解 --- 作者:TTT BLOG 本文地址:http://blog.chinaunix.net/u3/107265/showart_2192657.html --- 简介: ...
- Flume(4)实用环境搭建:source(spooldir)+channel(file)+sink(hdfs)方式
一.概述: 在实际的生产环境中,一般都会遇到将web服务器比如tomcat.Apache等中产生的日志倒入到HDFS中供分析使用的需求.这里的配置方式就是实现上述需求. 二.配置文件: #agent1 ...