14Spring_AOP编程(AspectJ)_环绕通知
在目标方法执行前后,进行代码增强 (阻止目标方法的执行 )
环绕通知实现任何通知效果。
案例如下:
案例结构:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASsAAAB1CAIAAACZNVDQAAAR00lEQVR4nO2dW4wb1RnHh4eKl0p9oBKPqFQFQlSpCbFZ3BAopSUqVVMVgRIJNptEsgIRIil3SEp3sxdnE+i0FBIEhIRLcJItpFA5RDSNeEhJopBV0iAkW7shuwvZ9a4Xry9rj73S9GFu5zoz3vV4ztjfTyNl58x3LnbO3+fMsc9/JFUATnQt+ey5n5rHy/dfh56e6FrS0Nak5IgUkVMNrdMt9W1bIirKCxX5PfcYye8GqKqqfvb04tSJvd+c3v/N6f3nDu/cu3k1evrZ04t9aldKjkjRhAiFeIPPChT4nWkgnivwxIkTsVjMIebJm785vV+Z+TRz/sBXn+zeu3k1enriyZu9biQHUKCnCPzONBBvFXj8+PHFixffcMMN9mGfbrn5m9P7M+cPZM4f+OrYHk2B5umnW/gKTMfj2x4+m3ZsSCIq6UTklN715CiSgqB3DCuLEUEUokXqmD0JT6MLYYaZtVrxRoFIekROWZ2W9xLMEiKyzBQY0iTGi+e2r5Y2s94rMlHG3pkWFqOHCtTkt3r1akcFHn30pnOHd371ye6vju35fF/Xs6vuRE+PPnqTbe7Rs3+/55Vt97yyrX+IHZCIkj0tEcV6ES0OtIfxCknJUeM8EdWLY/QkVufihElYbVYbSD1yX4KVTc9ICgwNYLykebw0VpvRsdXMxnoDzRJBgXXHlN+aNWvsFbhl+bUv33/d3s2rtePZVXc+u+rO+VSZjse33XPsSyqdMdciuogLBXImbNSwoH3Mo6HMzuUYZp7i6cQYSLwEopF0mx0DFvTSjFN8lNXzMOoCBaqqRwpE5eeoQFVVP9jwE3TpRVPgNdu/lK56UbrqxWu206pCcRoDPVIgOsaQHUjrvdpFm85lE+arAuf50hAF0sWCAjl4osBYLHYDQm9vr338wY4fEysxqqqa2pOuepGb09V9IDr1SshkVz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2wsCaGkWgUG5qs5Qazi/DSWSsxVsHoPSRRkZHqfiWGUiA3vJZCrGZgLaU/EqxPD7zl+t0fFQYKbARCKLDrmd9eTpcvT5ZGJssjk+WRtG42YTcF5cKbYtVrCR4A6okQCvzTU7/7eqJ0aaL0tXEsoDBQIBAkhFDg80+sIg4tHbV7cQ0oEAgSQigQAFoWUCAA+AkoEAD8BBQIAH4CCgQAPwEFAoCfgAIBwE/8V6AkSd+7+mr7Q5KY7azrr6KE9XoRtmFAPRBCgT94OG5/eKVActODkB1d2IYB9aCVFZiSI5GIoL0bfsHTKgihQDewsi5IgdrmAjunCD8BBbYKQihwvjGoAtmbfJD0iCzb7lNn9HkXljOUOwu5H4qRHYtHNx4aZUbMHUY2W5+w/baMFw4EA1EUaA50zNHPSYF2xirYnj9KbY4KdLac4dZu40xDb1cnyuRt/6UywmAZcERR4LwwFMgzViHSjVO2txF3DKRP8XSurQsnO9vNhVcXboHByEhYSwABQxQFEmOg6sYnxk6BLCsk/RSZtaEzx3oqkPaPULmfCw51OVtImUGgwyAiigIZ6Y4+MTazUOT2jDULxYogx0Br9d/Ocoa4qWPVbuNMQ7u5uFAgM2NKlhNUFiA4iKJAegzUr9r5xLhYiUEcXrCVGKQIewVyLWcSRDF07bzszMUTsky2CQ1r1YW51AMEBVEUyL40H58YPvbfPDjPQmsFBiXAGSEUSPwAbQFrMwQpOcJZsWSFUpdBgYDn+K9AG+blE4ODTNu48tOncbRYQIGA5witQABoekCBAOAnoEAA8BNQIAD4CSgQAPzk/1mhXh80lFn1AAAAAElFTkSuQmCC" alt="" />
第一步:编写代理类。
MyAspect.java
//这里必须要抛异常
public Object around( ProceedingJoinPoint proceedingJoinPoint) throws Throwable
{
System.out.print("环绕通知 方法前执行");
Object result=proceedingJoinPoint.proceed();
System.out.print("环绕通知 方法后执行");
return result; }
第二步:写ApplicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="OrderService" class="cn.itcast.spring.c_aop.impl.OrderServiceimpl" /> <!-- AspectJ AOP -->
<!-- 配置目标 -->
<bean id="CustomerService" class="cn.itcast.spring.d_aspectj.CustomerService"></bean>
<!-- 配置切面类 -->
<bean id="MyAspect" class="cn.itcast.spring.d_aspectj.MyAspect"></bean>
<aop:config>
<!-- ref引用切面类 -->
<aop:aspect ref="MyAspect"> <aop:pointcut expression="execution(* cn.itcast.spring.d_aspectj.CustomerService.*(..))" id="mypointcut2"/> <aop:around method="around" pointcut-ref="mypointcut2"/> </aop:aspect> </aop:config> </beans>
第三步 写Junit测试的代码:
@Test
public void testaround()
{ customerService.delete(); }
第四步 输出结果:
环绕通知 方法前执行
this is delete
环绕通知 方法后执行
14Spring_AOP编程(AspectJ)_环绕通知的更多相关文章
- 12Spring_AOP编程(AspectJ)_前置通知
接下里的博客会一篇一篇的讲解每一个通知.其实AOP_AspectJ的编程与传统的AOP的编程的最大的区别就是写一个Aspect 支持多个Advice和多个PointCut .而且我们写AOP_Aspc ...
- 16Spring_AOP编程(AspectJ)_最终通知
- 13Spring_AOP编程(AspectJ)_后置通知
后置通知和前置通知差不多.最大的特点是因为后置通知是运行在目标方法之后的,所以他可以拿到目标方法的运行的结果. 给出案例: 案例结构图:
- 15Spring_AOP编程(AspectJ)_抛出通知
- 11Spring_AOP编程(AspectJ)_概述
AspectJ 是一个框架 (第三方AOP框架 ),提供切面编程 ,编写一个Aspect 支持多个Advice和多个PointCut .对比前一种提到的传统的Aop编程,AspctJ更加的常用.Asp ...
- 19Spring_AOP编程(AspectJ)_使用@Pointcut注解来定义切点
我们之前的方式是采用 @AfterReturning(value="execution(* com.guigu.shen.anotion.UserDaoImpl.*(..))",r ...
- spring框架应用系列四:切面编程(环绕通知与前后置通知区别)
切面编程(环绕通知与前后置通知区别) 本文系作者原创,转载请注明出处:http://www.cnblogs.com/further-further-further/p/7867034.html 解决问 ...
- AOP 环绕通知 (Schema-base方式) 和 AspectJ方式在通知中获取切点的参数
环绕通知(Schema- base方式) 1.把前置通知和后置通知都写到一个通知中,组成了环绕通知 2.实现步骤: 2.1 新建一个类实现 MethodInterceptor 接口 public cl ...
- 18Spring_AOP编程(AspectJ)_AspectJ的各种通知总结
小结: 前置通知(权限控制). 后置通知 ---- 不怎么用 环绕通知(权限控制. 性能监控. 缓存技术 ) 异常通知 (发生异常后, 记录错误日志 ) 最终通知 (释放资源 ) 环绕通知 是取代任何 ...
随机推荐
- linux网络流量实时监控工具之iptraf
这个工具还是很强大 linux网络流量实时监控工具之iptraf [我的Linux,让Linux更易用]IPTraf是一个网络监控工具,功能比nload更强大,可以监控所有的流量,IP流量,按协议分的 ...
- android Java BASE64编码和解码一:基础
今天在做Android项目的时候遇到一个问题,需求是向服务器上传一张图片,要求把图片转化成图片流放在 json字符串里传输. 类似这样的: {"name":"jike&q ...
- 浅谈DES加密算法
一.DES加密算法介绍 1.要求密钥必须是8个字节,即64bit长度 2.因为密钥是byte[8] , 代表字符串也可以是非可见的字节,可以与Base64编码算法一起使用 3.加密.解密都需要通过字节 ...
- win7操作技巧
Q : 打开文件夹默认最大化A :随便打开一个文件夹 鼠标移动到左上角 然后点击鼠标左键 选择“最大化” 后关闭 之后每次打开就是最大化了
- genymotion虚拟机启动失败
错误提示如下: Make sure that you have installed it correctly before starting Genymotion. 解决方法(重启VirtualBox ...
- Html5如何使我们开发出来的应用或页面大小能适合各种高端手机使用
本文简介:1.手机移动端页面的自适应2.手机触摸手动滑动效果 一.header信息的设置(自适应) 1.声明信息 <!DOCTYPE HTML> 2.编码设置 <meta chars ...
- Effective Java 42 Use varargs judiciously
Implementation theory The varargs facility works by first creating an array whose size is the number ...
- Effective Java 44 Write doc comments for all exposed API elements
Principle You must precede every exported class, interface, constructor, method, and field declarati ...
- Buffer篇
// var buf1 = new Buffer(26);/*返回一个新的buffer对象,这个新buffer和老buffer公用一个内存.但是被start和end索引偏移缩减了.(比如,一个buff ...
- nginx 与 lua 开发环境搭建
首先下载最新版的 相关软件 的安装文件. nginx: http://nginx.org/en/download.html LuaJIT: http://luajit.org/download.htm ...