您的位置:首页 > 编程语言 > Java开发

spring aop 配置使用说明

2015-11-26 15:58 399 查看
<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.*(..))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: