示例代碼:
定義切面,在 * tdxy..service.*ServiceImpl.(..) 中執行有關的hibernate session的事務操作
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(*
org.dcc.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
在上面的代碼中
execution 是方法運行
public 是指定public的方法,也可以不寫直接:execution(* cn.dao.IUserDAO.*(..)
* 是任意返回值,可以有返回值,也可以是void沒有返回值的方法
cn.dao.IUserDAO.* 是指定目錄下的指定類任意方法
cn.dao.IUserDAO.insert* 是指定目錄下的指定類insert開頭的任意方法
cn.dao.IUserDAO.*.* 是指定目錄下的任意類下的任意方法
cn.dao..*.* 是指定目錄下的任意目錄下任意類下的任意方法
(..) 是任何參數,可以是沒有參數
在execution中是可以有多個的方法,例如:
execution(* com.action.userinfoAction..*(..))&&execution(* com.action.memberAction..*(..))&&!execution(* get*(..))&&!execution(* set*(..))
應該寫的明白了吧?