(五)在XML中声明切面
Spring的AOP配置原素能够以非侵入性的方式声明切面
AOP配置元素 | 用途 |
---|---|
<aop:advisor> | 定义AOP通知器 |
<aop:after> | 定义后置通知 |
<aop:after-returning> | 定义AOP返回通知 |
<aop:after-throwing> | 定义AOP异常通知 |
<aop:around> | 定义AOP环绕通知 |
<aop:aspect> | 定义一个切面 |
<aop:aspectj-autoproxy> | 启用@AspectJ注解驱动的切面 |
<aop:before> | 定义AOP前置通知 |
<aop:config> | 顶层的AOP配置元素.大多数的<aop:*> 元素必须包含在<aop:config>内 |
<aop:declare-parent> | 以透明的方式为被通知的对象引入额外的接口 |
<aop:pointcut> | 定义一个切点 |
//例:
<bean id="audience1" class="com.ty.xml.Audience1"></bean>
<aop:config>
//定义切面
<aop:aspect ref="audience1">
//定义通用的切点表达式
//定义前置通知
<aop:before method="silenceCellPhones" pointcut-ref="pointcut"/>
<aop:before method="takeSeats" pointcut-ref="pointcut"/>
//定义后置通知
<aop:after-returning method="applause" pointcut="execution(* com.ty.concert.*.perform(..))"/>
//定义异常通知
<aop:after-throwing method="demandRefund" pointcut="execution(* com.ty.concert.*.perform(..))"/>
//引入通知
<aop:declare-parents types-matching="com.ty.concert.Performance+" implement-interface="com.ty.concert.Encoreable"
default-impl="com.ty.concert.DefaultEncoreable" ></aop:declare-parents>
//若IOC容器中存在DefaultEncoreable对应的bean
<aop:declare-parents types-matching="com.ty.concert.Performance+" implement-interface="com.ty.concert.Encoreable"
default-ref="defaultEncoreable" ></aop:declare-parents>
</aop:aspect>
</aop:config>
(六)注入AspectJ切面
参考:http://blog.csdn.net/u012523359/article/details/72851479