<aop:config>标签
- <bean id="profiler" class="SimpleProfiler"/> //这是你要进行对切面拦截处理的另一个定义的类
- <aop:config>
- <aop:aspect ref="profiler">
- <aop:pointcut id="aopafterMethod" expression="execution(* FooService.*(..))"/> //定义的切面 即你要进行拦截的类
- <aop:after pointcut-ref="aopafterMethod" method="afterMethod"/>//拦截类执行后再去执行你定义的类 红色是你定义类的方法名
- <aop:pointcut id="aopBefore" expression="execution(* FooService.getBefore(String)) and args(myName)"/> 切面
- <aop:before pointcut-ref="aopBefore" method="beforeMethod"/> 执行拦截前 执行你定义的类
- </aop:aspect>
- </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.*(..))
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.*(..))