本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7592357
建立时间:2006年5月29日




[Spring]spring 2.0 aop编程(一)
软件技术

lhwork 发表于 2006/12/30 10:09:16

在spring2.0中,aop发生了很大的变化:主要分为两大方面1.支持简单的aop xml配置2.支持@AspectJ的注释先来看一看第一种情况:申明一个aspect,在xml中的申明如下: <aop:config>   <aop:aspect id="myAspect" ref="aBean">     ...   </aop:aspect> </aop:config> <bean id="aBean" class="...">   ... </bean> 申明pointcut <aop:config>   <aop:pointcut id="businessService"         expression="execution(* com.xyz.myapp.service.*.*(..))"/> </aop:config> 申明advice Before advice: <aop:aspect id="beforeExample" ref="aBean">     <aop:before       pointcut-ref="dataAccessOperation"       method="doAccessCheck"/> </aop:aspect> After returning advice: <aop:aspect id="afterReturningExample" ref="aBean">       <aop:after-returning       pointcut-ref="dataAccessOperation"       method="doAccessCheck"/>               ...     </aop:aspect> 或者带有返回参数 <aop:aspect id="afterReturningExample" ref="aBean">       <aop:after-returning       pointcut-ref="dataAccessOperation"       returning="retVal"       method="doAccessCheck"/>               ...     </aop:aspect>   After throwing advice: <aop:aspect id="afterThrowingExample" ref="aBean">       <aop:after-throwing       pointcut-ref="dataAccessOperation"       method="doRecoveryActions"/>               ...     </aop:aspect> 或者带有throwing <aop:aspect id="afterThrowingExample" ref="aBean">       <aop:after-throwing       pointcut-ref="dataAccessOperation"       throwing="dataAccessEx"       method="doRecoveryActions"/>               ...     </aop:aspect> After (finally) advice: <aop:aspect id="afterFinallyExample" ref="aBean">       <aop:after       pointcut-ref="dataAccessOperation"       method="doReleaseLock"/>               ...     </aop:aspect> Around advice: <aop:aspect id="aroundExample" ref="aBean">       <aop:around       pointcut-ref="businessService"       method="doBasicProfiling"/>               ...     </aop:aspect> Advice parameters: <aop:before   pointcut="Pointcuts.anyPublicMethod() and @annotation(auditable)"   method="audit"   arg-names="auditable"/> 对于引入接口(Introductions): <aop:aspect id="usageTrackerAspect" ref="usageTracking">   <aop:declare-parents       types-matching="com.xzy.myapp.service.*+",       implement-interface="UsageTracked"      default-impl=" service.tracking.DefaultUsageTracked"/>   <aop:before     pointcut="com.xyz.myapp.SystemArchitecture.businessService()               and this(usageTracked)"     method="recordUsage"/> </aop:aspect>


阅读全文(3610) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.172 second(s), page refreshed 144772516 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号