spring aop 配置使用说明

<aop:config>标签


  1. <bean id="profiler" class="SimpleProfiler"/>    //这是你要进行对切面拦截处理的另一个定义的类
  2.   
  3.  <aop:config>  
  4.   
  5. <aop:aspect ref="profiler">  
  6.   
  7.  <aop:pointcut id="aopafterMethod"  expression="execution(* FooService.*(..))"/>  //定义的切面  即你要进行拦截的类
  8.   
  9. <aop:after pointcut-ref="aopafterMethod" method="afterMethod"/>//拦截类执行后再去执行你定义的类 红色是你定义类的方法名
  10.   
  11.   
  12. <aop:pointcut id="aopBefore"  expression="execution(* FooService.getBefore(String)) and args(myName)"/>  切面
  13.   
  14. <aop:before pointcut-ref="aopBefore"  method="beforeMethod"/>   执行拦截前 执行你定义的类
  15.   
  16. </aop:aspect>  
  17.   
  18. </aop:config>  
  另注
 expression="execution(  表达式说明

任意公共方法的执行:
execution(public * *(..))
任何一个以“set”开始的方法的执行:
execution(* set*(..))
AccountService 接口的任意方法的执行:
execution(* com.xyz.service.AccountService.*(..))
定义在service包里的任意方法的执行:
execution(* com.xyz.service.*.*(..))
定义在service包和所有子包里的任意类的任意方法的执行:
execution(* com.xyz.service..*.*(..))
定义在pointcutexp包和所有子包里的JoinPointObjP2类的任意方法的执行:
execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
***> 最靠近(..)的为方法名,靠近.*(..))的为类名或者接口名,如上例的JoinPointObjP2.*(..))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值