Spring的AOP实现是通过集成AspectJ框架实现的。

想必这句话大家都知道了吧,不知道也没关系,最起码你现在知道了。

四种实现方案,接下来我们一一去揭开它的神秘的面纱.......

第一种(伪代码的形式)

经典AOP形式的:

<bean id="userDao" class="UserDaoImpl"></bean>

<bean id="service" class="UserServiceImpl">

<property name="dao" ref="userDao"></property>

</bean>

<bean id="myBefore" class="MyBeforeAdvice"></bean>

<bean id="myAfter" class="MyAfterAdvice"></bean>

<aop:config>

<aop:pointcut id="point" expression="execution(* *..biz.*.*(..))"></aop:pointcut>

<aop:advisor pointcut-ref="point" advice-ref="myBefore"></aop:advisor>

<aop:advisor pointcut-ref="point" advice-ref="myAfter"></aop:advisor>

</aop:config>

第二种(伪代码形式)

使用注解方式

@Aspect

public class MyBeforeAspect{

@Before(value="execution(* *..biz.*.*(..))")

public void before(){

System.out.println("====before===");

}

@AfterReturning(value="execution(* *..biz.*.*(..))")

public void after(){

System.out.println("=====after=====");

}

}

<bean id="stuDao" class="StudentDaoImpl"></bean>

<bean id="stuService" class="StudentService">

<property name="dao" ref="stuDao">

</bean>

<!-- 准备aop:aspectj-autoproxy-->

<bean class="MyBeforeAspect"></bean>

<aop:aspectj-autoproxy />

第三种(伪代码形式)

使用AspectJ基于xml形式

public class MyAspectJMethod{

public void myBefore(){

System.out.println("AspectJ=========before");

}

public void myAfter(){

System.out.println("AspectJ==========after");

}

}

<bean id="stuDao" class="StudentDaoImpl"></bean>

<bean id="stuBiz" class="StudentBizImpl"></bean>

<bean id="myAspectJ" class="MyAspectJMethod">

<aop:config>

<aop:pointcut id="point" expression="execution(* *..biz.*.*(..))"></aop:pointcut>

<aop:aspect ref="myAspectJ">

<aop:before method="myBefore" ponitcut-ref="point"></aop:before>

<aop:after method="myAfter" pointcut-ref="point"></aop:after>

</aop:aspect>

</aop:config>

上面配置<aop:pointcut>节点也可以放到<aop:aspect>节点内,如下:

<aop:config>

<aop:aspect ref="myAspectJ">

<aop:pointcut id="point" expression="execution(* *..biz.*.*(..))"></aop:pointcut>

<aop:before method="myBefore" ponitcut-ref="point"></aop:before>

<aop:after method="myAfter" pointcut-ref="point"></aop:after>

</aop:aspect>

</aop:config>

上述两种配置都可以实现该功能。。。。。

Spring 中面向AOP之一系列做法的更多相关文章

  1. Spring AOP——Spring 中面向切面编程

    前面两篇文章记录了 Spring IOC 的相关知识,本文记录 Spring 中的另一特性 AOP 相关知识. 部分参考资料: <Spring实战(第4版)> <轻量级 JavaEE ...

  2. Spring中的AOP 专题

    Caused by: java.lang.IllegalArgumentException: ProceedingJoinPoint is only supported for around advi ...

  3. (五)Spring 中的 aop

    目录 文章目录 AOP概念 AOP原理 AOP术语 **`Spring`** 中的 **`aop`** 的操作 使用 `AspectJ` 实现 `aop` 的两种方式 AOP概念 浅理解 aop :面 ...

  4. Spring中的AOP

    什么是AOP? (以下内容来自百度百科) 面向切面编程(也叫面向方面编程):Aspect Oriented Programming(AOP),通过预编译方式和运行期动态代理实现程序功能的统一维护的一种 ...

  5. Spring中关于AOP的实践之概念

    一.什么是AOP AOP:也称作面向切面编程 在分享几个概念执行我想先举个栗子(可能例子举得并不是特别恰当): 1.假如路人A走在大街上,被一群坏人绑架了: 2.警察叔叔接到报警迅速展开行动:收集情报 ...

  6. Spring学习笔记(四)—— Spring中的AOP

    一.AOP概述 AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...

  7. 2018.12.24 Spring中的aop演示(也就是运用aop技术实现代理模式)

    Aop的最大意义是:在不改变原来代码的前提下,也不对源代码做任何协议接口要求.而实现了类似插件的方式,来修改源代码,给源代码插入新的执行代码. 1.spring中的aop演示 aop:面向方面编程.不 ...

  8. JavaWeb_(Spring框架)认识Spring中的aop

    1.aop思想介绍(面向切面编程):将纵向重复代码,横向抽取解决,简称:横切 2.Spring中的aop:无需我们自己写动态代理的代码,spring可以将容器中管理对象生成动态代理对象,前提是我们对他 ...

  9. spring中的AOP 以及各种通知 配置

    理解了前面动态代理对象的原理之后,其实还是有很多不足之处,因为如果在项目中有20多个类,每个类有100多个方法都需要判断是不是要开事务,那么方法调用那里会相当麻烦. spring中的AOP很好地解决了 ...

随机推荐

  1. include与file_get_contents区别

    参考:http://www.cnblogs.com/bgwan/archive/2013/03/13/2957215.html 一,先来说file_get_contents         这个函数就 ...

  2. Java并发工具类之并发数控制神器Semaphore

    Semaphore(信号量)使用来控制通知访问特定资源的线程数量,它通过协调各个线程,以保证合理的使用公共资源. 我们可以这么理解Semaphore,比如一个厕所只有6个坑,同时只能满足6个人上厕所( ...

  3. 【GDOI2018模拟8】 数学竞赛 三角函数性质+记忆化搜索

    数据范围:p,q≤20. 只能说我整个人傻逼了..... 我们考虑三角函数的部分性质: $sin(x)=\sqrt{ 1-cos^2(x)}$ $cos(x)=\sqrt{1-sin^2(x)}$ $ ...

  4. WebDriverAPI(2)

    操作浏览器窗口 被测网址http:http://www.baidu.com Java语言版本的API实例代码 String url = "http://www.baidu.com" ...

  5. celery问题记录

    1. 问题:WARNING/MainProcess] /home/jihonghe/.virtualenvs/py3_dj217_env/lib/python3.6/site-packages/bil ...

  6. VSTO学习(六)——创建Outlook解决方案

    本专题概要 引言 Outlook对象模型 自定义Outlook窗体 小结 一.引言 在上一个专题中,为大家简单介绍了下如何创建Word解决方案的,所以本专题中将为大家介绍下Outlook相关的内容.我 ...

  7. (转)http://blog.csdn.net/renfufei/article/details/38474435

    原文:http://blog.csdn.net/renfufei/article/details/38474435

  8. Django和DateTimeField

    问一下大家,你们用ORM创建表的时候,DateTimeField字段中的数据取出来放在前端,你们都是怎么做的? 不满你们说,我以前要不然是使用默认的方法,要不然就是自己写个tag或者其他的来格式化一下 ...

  9. java 中几种常用数据结构

    Java中有几种常用的数据结构,主要分为Collection和map两个主要接口(接口只提供方法,并不提供实现),而程序中最终使用的数据结构是继承自这些接口的数据结构类. 一.几个常用类的区别 1.A ...

  10. 【java排序】 选择排序,插入排序,希尔算法

    一.选择排序 1.基本思想:在要排序的一组数中,选出最小的一个数与第一个位置的数交换:然后在剩下的数当中再找最小的与第二个位置的数交换,如此循环到倒数第二个数和最后一个数比较为止. 2.实例 3.算法 ...