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 ...
随机推荐
- css-关于文本
1. 使用 text-overflow:ellipsis; 超出部分会变成省略号 http://www.w3school.com.cn/tiy/t.asp?f=css3_text-overflow 1 ...
- JSP页面JSTL提供的函数标签EL表达式操作字符串的方法
首先在jsp页面导入标签<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions&quo ...
- Android源码阅读 – Zygote
@Dlive 本文档: 使用的Android源码版本为:Android-4.4.3_r1 kitkat (源码下载: http://source.android.com/source/index.ht ...
- Mac系统下开启和关闭隐藏文件的方法
在Mac下找到终端,输入以下命令(注意区分大小写): 显示Mac隐藏文件的命令: defaults write com.apple.finder AppleShowAllFiles -bool tru ...
- 虚拟机安装windows服务出现无法打开内核设备“\\.Global\vmx86”
解决方法: 在cmd下依次输入net start vmci,net start vmx86,net start VMnetuserif三个命令即可
- windows下webstorm开发react-native智能提示
webstorm破解版地址:点这里 1.随便在一个目录下下载ReactNative-LiveTemplate插件,命令为: git clone https://github.com/virtoolsw ...
- android 去掉actionbar 的虚线
if(Build.VERSION.SDK_INT>=21){ getSupportActionBar().setElevation(0); }
- 配置Samba共享服务器
安装samba: sudo apt-get install samba samba-common 由于是挂载另一个磁盘,并作为共享文件存放地: 列出磁盘名和ID air@air-device:~$ s ...
- mysql事务
1. 事务并不专属于mysql 2. 事务的ACID特性 1)原子性(atomicity) 一个事务必须被视为一个不可分割的最小工作单元,整个事务中得所有操作要么全部提交成功,要么全部失败回滚,对于一 ...
- 感知机(perceptron)概念与实现
感知机(perceptron) 模型: 简答的说由输入空间(特征空间)到输出空间的如下函数: \[f(x)=sign(w\cdot x+b)\] 称为感知机,其中,\(w\)和\(b\)表示的是感知机 ...