后置通知和前置通知差不多。最大的特点是因为后置通知是运行在目标方法之后的,所以他可以拿到目标方法的运行的结果。

给出案例:

案例结构图:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARYAAAB9CAIAAADoa9s1AAASe0lEQVR4nO2dW2wU1xnHTx6qvlTqQyrlMWqrJiGoVW1s2k4pTa9BbVWqpgGcxpQ00igJigptc+FiiM3iWISk0yYpuQAxuYBr3JYGMgRRQpFKMbk4hSYNYmSMiQF77TWLr7te0+nDzM6c68ysZ8dzxv5++h52zn7nMrvnv+fM7JzvIHPauXii+V+bv4TbxRPN098MACgLKO4GAECyAQkBQChAQgAQCpAQAIQCJAQAoQAJAUAoJJLQ6gU3xFm9oSlI0Yw4myCkvG3TVVlOVObPPDBxSuhoQ8WxtV907Ok7b8QPjzZUTGtrZP46QUISE6eEjj0y1zi68+LJXRdP7urY+8TOVcvww2OPzI2pXYamIFWXoZBoiFlCEn8yUyIqCR09erSpqcnH56FbL57clb96OHNq90dvbtu5ahl+ePShWyNqmx8goUiR+JOZEpFI6MiRI3Pnzr3pppu83Q6vvvXiyV2ZU7szp3Z/dOg5S0LO4eHVYgmlW1rq7n837dsQXUU2imbYfUdTsRQM+5t1sxQ9qEIsTxunK5BpbCFcN6dW179YIJauaIbb60Sn4JSgaBpXIViTOCcvbF8pbeZ9VnSiRnwyM0JN5ZeQpZ9ly5b5Sujgg7d07H3ioze3fXTouRPNDWsW34YfHnzwFs/cH7/7zO3P1t3+bN2WTr6DrtJdRVeJbsD2bryLiAoxNLV4rKt2cZyuwOsdAjdE1Oa2gRaU8BTcbHZGWiG4A+eUpnBqvDbjo5uTjfcBOiWChFgc/dTU1HhLaPWCG56+88adq5ZZtmbxbWsW3zaVKtMtLXW3H/qQSedMV6jvOICEBHMe5ofZ+qHFXbm9w9fNOSTTqVGIOgWqkWybfR1CnVrxkBzn7DycukBCYnD9+ErINM2/3PsF/P6BJaHrN32IrnsSXffk9ZtYWeD4jUIRSQj/lad7gNX9rDc9eo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不多,这里每个类就不做具体解释了。

第一步:

编写目标类:

package cn.itcast.spring.d_aspectj;

//目标业务类
public class CustomerService { public int delete() {
System.out.println("this is delete");
return 1;
} }

第二步:

编写切面类

//切面类(内部可以写很多的Advice的方法)
public class MyAspect { //可以传两个参数,后置通知相比前置通知来时
//一个特点是,因为后置通知是运行在目标方法之后的,所以他可以拿到目标方法的运行的结果
public void afterReturning(JoinPoint joinPoint,Object result)
{
System.out.print("后置通知的运行"+result); } }

第三步:编写Spring配置文件

<!-- 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"/> <!-- 这个参数是配置返回的 必须和public void afterReturning(JoinPoint joinPoint,Object result)这个方法里面的 result一字不差-->
<aop:after-returning method="afterReturning" returning="result" pointcut-ref="mypointcut2" />
</aop:aspect>

第三步:编写测试类

    @Test
public void testafter()
{System.out.print(customerService.getClass().getName());
customerService.delete(); }

输出结果:

this is delete
后置通知的运行1

看到没  !返回了目标函数的执行结果。

13Spring_AOP编程(AspectJ)_后置通知的更多相关文章

  1. 15Spring_AOP编程(AspectJ)_抛出通知

  2. Spring -- aop(面向切面编程),前置&后置&环绕&抛异常通知,引入通知,自动代理

    1.概要 aop:面向方面编程.不改变源代码,还为类增加新的功能.(代理) 切面:实现的交叉功能. 通知:切面的实际实现(通知要做什么,怎么做). 连接点:应用程序执行过程期间,可以插入切面的地点. ...

  3. AOP 和 前置通知,后置通知

    Spring 1.AOP:中文名称面向切面编程 2.英文名称:(Aspect Oriented Programming) 3.正常程序执行流程都是纵向执行流程 3.1 又叫面向切面编程,在原有纵向执行 ...

  4. [原创]java WEB学习笔记106:Spring学习---AOP的通知 :前置通知,后置通知,返回通知,异常通知,环绕通知

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  5. spring 切面 前置后置通知 环绕通知demo

    环绕通知: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...

  6. Spring AOP前置通知和后置通知

    Spring AOP AspectJ:Java社区里最完整最流行的AOP框架 在Spring2.0以上的版本中,可以使用基于AspectJ注解或基于XML配置的AOP 在Spring中启用Aspect ...

  7. spring学习 十 schema-based 前置后后置通知

    spring 提供了 2 种 AOP 实现方式:(1)Schema-based ,(2)AspectJ Schema-based:每个通知都需要实现接口或类,配置 spring 配置文件时在<a ...

  8. Spring初学之xml实现AOP前置通知、后置通知、返回通知、异常通知等

    实现两个整数的加减乘除,在每个方法执行前后打印日志. ArithmeticCalculator.java: package spring.aop.impl.xml; public interface ...

  9. Spring初学之annotation实现AOP前置通知、后置通知、返回通知、异常通知。

    实现两个整数的加减乘除.在执行每个方法之前打印日志. ArithmeticCalculator.java: package spring.aop.impl; public interface Arit ...

随机推荐

  1. ABAP程序中退出操作(CHECK, EXIT, RETURN, LEAVE PROGRAM)

    这里总结一下几个常用的退出操作:  CHECK.(SAP官方推荐只在循环中使用) 1)CHECK 后面要跟一个表达式,当表达式值为假(false)时,CHECK发生作用,退出循环(LOOP)或处理程序 ...

  2. Atitit.木马病毒的免杀原理---sikuli 的使用

    Atitit.木马病毒的免杀原理---sikuli 的使用 1. 使用sikuli java api1 1.1. 3. Write code!1 2. 常用api2 2.1. wait 等待某个界面出 ...

  3. How to Use Telnet to Test SMTP Communication

    Topic Last Modified: 2005-05-24 Telnet is an extremely useful tool for troubleshooting issues relate ...

  4. How to copy files between sites using JavaScript REST in Office365 / SharePoint 2013

    http://techmikael.blogspot.in/2013/07/how-to-copy-files-between-sites-using.html I'm currently playi ...

  5. 转:在浏览器地址栏按回车、F5、Ctrl+F5刷新网页的区别

    转:http://www.cnblogs.com/mofish/archive/2012/06/08/2541604.html 不少同学问,不都是刷新吗?还有什么区别?其实,还是有的. 其中,在地址栏 ...

  6. 【原】visual studio添加现有文件夹的方法

    由于使用版本管理器协调工作,有时同事就直接上传文件夹了,但右键添加现有项时不能添加文件夹的. 在工具栏"项目"下面有个"显示所有文件",选择这个,整个工程的文件 ...

  7. eclipse 中手动安装 subversive SVN

    为什么我选择手动安装呢?因为通过 eclipse market 下载实在太慢了.   1.下载离线安装包 http://www.eclipse.org/subversive/latest-releas ...

  8. docker-2 深入了解docker

    docker镜像.容器.仓库的基本概念 镜像 Docker 镜像就是一个只读的模板.例如:一个镜像可以包含一个完整的 CentOS 操作系统环境,里面仅安装了 httpd或用户需要的其它应用程序. 镜 ...

  9. oc-基本语法

    一.第一个oc程序 #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { NSLog(@& ...

  10. UVALive 6073 Math Magic

                                                  6073 Math MagicYesterday, my teacher taught us about m ...