- 声明一个切面
切面使用<aop:aspect/>来声明
<aop:config>
<aop:aspect id="myAspect" ref="aBean">
...
</aop:aspect>
</aop:config>
<bean id="aBean" class="..."/>
-
声明一个切入点
<aop:config>
<aop:aspect id="myAspect" ref="aBean">
<aop:pointcut id="logService" expression="execution(* com.pms.service.*.*(..))"/>
<aop:before pointcut-ref="logService" method="log"/>
</aop:aspect>
</aop:config>
<bean id="aBean" class="..."/>
- 声明通知
//前置通知
<aop:before pointcut-ref="..." method="..."/>
//后置通知
<aop:after-returing pointcut-ref="..." method="..." returing="..."/>
//异常通知
<aop:after-throwing pointcut-ref="..." method="..." throwing="..."/>
//最终通知
<aop:after pointcut-ref="..." method="..."/>
//环绕通知
<aop:around pointcut-ref="..." method="..."/>
- 定义切面的4种方式
1.基于@AspectJ注解的方式
2.基于<aop:aspect>的方式
3.基于<aop:advisor>的方式
4.基于Advisor类的方式
- Spring AOP中使用@AspectJ还是XML?
Java5以下只能选择XML方式,XML风格有个缺点,不能完全将需求实现的地方封装到一个位置。