SpringAop 9 (面向切面编程,常用于拦截器)

来源:互联网 发布:儿童学唱歌软件 编辑:程序博客网 时间:2024/06/17 12:53

spring 中aop 的概念

Advices :表示一个 method 执行前或执行后的动作。
Pointcut :表示根据 method 的名字或者正则表达式去拦截一个 method 。
Advisor : Advice 和 Pointcut 组成的独立的单元,并且能够传给 proxy factory 对象。

对于拦截

before after around 有时候会有异常抛出语句
这些关键词在 class 中的路径中进行使用

指向性的切点拦截

通过 pointcut 方法 和Advisor 方法来进行拦截

在配置bean文件中,进行配置:

<bean id="customerPointcut"     class="org.springframework.aop.support.NameMatchMethodPointcut"> <property name="mappedName" value="printName" />

这个方法是通过Name match example来实现的

第二种方法 利用正则表达式来进行