下载此文档

spring4中文技术手册==.docx


文档分类:IT计算机 | 页数:约5页 举报非法文档有奖
1/5
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/5 下载此文档
文档列表 文档介绍
spring4中文技术手册
在《静态代理和动态代理》中提到了面向方面编程,主要就是基于动态代理。单独抽象出非业务的功能,服务于某些业务方法。Spring提供了四种很实用的Advice,分别为:Before Advice, After Returning Advice, Around Advice, After throwing Advice。都是方法级别的,就是在某个方法执行前后插入一些非业务的操作,如打日志或者判断权限等。
对于这四种advice的实现,spring都提供了三种方法,分别为基于接口、基于xml和基于annotation(注释)。Before Advice会在目标对象的方法执行之前被调用;After Advice会在目标方法执行之后被调用;Around Advice则可以在目标方法执行前后同时加上相关服务;Throw Advice是在异常发生后执行某些操作。

这个就需要自定义的Aspect实现Spring接口。
.:
/** 
 * Advice invoked before a method is invoked. Such advices cannot 
 * prevent the method call proceeding, unless they throw a Throwable. 
 */  
public interface MethodBeforeAdvice extends BeforeAdvice {  
      
    /** 
     * Callback before a given method is invoked. 
     * ***@param method method being invoked 
     * ***@param args arguments to the method 
     * ***@param target target of the method invocation. May be <code>null</code>. 
     * ***@throws Throwable if this object wishes to abort the call. 
     * Any exception thrown will be returned to the caller if it's 
     * allowed by the method signature. Otherwise the exception 
     * will be wrapped as a runtime exception. 
     */  
    void before(Method method, Object[] args, Object target) throws Throwable;  
}  
 
After .:
/** 
 * After returning advice is invoked only on norma

spring4中文技术手册== 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数5
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小61 KB
  • 时间2017-11-18