歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 關於aop:pointcut的expression配置說明及JoinPoint

關於aop:pointcut的expression配置說明及JoinPoint

日期:2017/3/1 9:15:02   编辑:Linux編程

關於aop:pointcut的expression配制說明及JoinPoint
我的示例如下,配制了多個pointcut:
<bean id="logAspect" class="com.abc.aspect.LogAspect">
<property name="logBiz" ref="logBiz" />
</bean>

<aop:config>
<aop:pointcut id="pointcut_add" expression="execution(* com.abc..biz..*.add*(..))"/>
<aop:pointcut id="pointcut_update" expression="execution(* com.abc..biz..*.update*(..))"/>
<aop:pointcut id="pointcut_delete" expression="execution(* com.abc..biz..*.delete*(..))"/>
<aop:aspect ref="logAspect">
<aop:after pointcut-ref="pointcut_add" method="log" />
<aop:after pointcut-ref="pointcut_update" method="log" />
<aop:after pointcut-ref="pointcut_delete" method="log" />
</aop:aspect>
</aop:config>
expression說明:
expression是對方法簽名的通配.本例中分為兩部分
第一個空格前是說明ret-type-pattern,空格後是說明name-pattern(param-pattern),具體說明如下:
第一個*(ret-type-pattern), 表示任意返回值類型
第二個和第三個*(name-pattern), 第二個包名通配,第三個方法名通配
最後二個.. 表示通配方法可以有0個或多個參數


##################################################
以下為網上文檔:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)throws-pattern?)

returning type pattern,name pattern, and parameters pattern是必須的.
ret-type-pattern:可以為*表示任何返回值,全路徑的類名等.
name-pattern:指定方法名,*代表所以,set*,代表以set開頭的所有方法.
parameters pattern:指定方法參數(聲明的類型),(..)代表所有參數,(*)代表一個參數,(*,String)代表第一個參數為任何值,第二個為String類型.

JoinPoint實用方法說明:

java.lang.Object[] getArgs():獲取連接點方法運行時的入參列表;
Signature getSignature() :獲取連接點的方法簽名對象;
java.lang.Object getTarget() :獲取連接點所在的目標對象;
java.lang.Object getThis() :獲取代理對象本身;

網上其它示例1:
<aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))" />

第一個* 表示任意返回值類型
第二個* 表示以任意名字開頭的package. 如 com.xx.
第三個* 表示以任意名字開頭的class的類名 如TestService
第四個* 表示 通配 *service下的任意class
最後二個.. 表示通配 方法可以有0個或多個參數

網上其它示例2:
execution(* com.aptech.jb.epet.dao.hibimpl.*.*(..))
這樣寫應該就可以了
這是com.aptech.jb.epet.dao.hibimpl 包下所有的類的所有方法。。
第一個*代表所有的返回值類型
第二個*代表所有的類
第三個*代表類所有方法
最後一個..代表所有的參數。

Spring中如何配置Hibernate事務 http://www.linuxidc.com/Linux/2013-12/93681.htm

Struts2整合Spring方法及原理 http://www.linuxidc.com/Linux/2013-12/93692.htm

基於 Spring 設計並實現 RESTful Web Services http://www.linuxidc.com/Linux/2013-10/91974.htm

Spring-3.2.4 + Quartz-2.2.0集成實例 http://www.linuxidc.com/Linux/2013-10/91524.htm

使用 Spring 進行單元測試 http://www.linuxidc.com/Linux/2013-09/89913.htm

運用Spring注解實現Netty服務器端UDP應用程序 http://www.linuxidc.com/Linux/2013-09/89780.htm

Spring 3.x 企業應用開發實戰 PDF完整高清掃描版+源代碼 http://www.linuxidc.com/Linux/2013-10/91357.htm

Spring 的詳細介紹:請點這裡
Spring 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved