溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

spring?aop?pointcut怎么添加多個execution

發(fā)布時間:2021-11-24 11:09:49 來源:億速云 閱讀:512 作者:小新 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)spring aop pointcut怎么添加多個execution,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

spring aop pointcut 添加多個execution

spring aop添加多個包,用||或者or隔開

<!-- 只對業(yè)務(wù)邏輯層實施事務(wù) -->
 <aop:config expose-proxy="true">
  <aop:pointcut expression="execution(* demo.ssh.daoImpl.*.*(..)) || execution(* demo.mes.daoImpl.*.*(..))"  
   id="txPointcut" />
  <!-- Advisor定義,切入點和通知分別為txPointcut、txAdvice -->
  <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />
 </aop:config>

spring aop:pointcut--expression--多個execution連接

聲明式事務(wù),多個execution連接方法:

expression="execution(* pp.business.*.*(..)) or execution(* pp.business.impl.*.*(..))"

spring的幫助手冊里有關(guān)于execution的連接方式的一句話:

Pointcut expressions can be combined using '&&', '||' and '!'.

但是我寫上&&就會報錯。很郁悶。。。

||和or的作用相同:在符合* pp.business.*.*(..)和* pp.business.impl.*.*(..)方法上都加上事務(wù)性。

<tx:advice id="txAdvice" transaction-manager="transactionManager">  
        <tx:attributes >  
        <tx:method name="add*" propagation="REQUIRED"/>  
        <tx:method name="delete*" propagation="REQUIRED"/>  
        <tx:method name="update*" propagation="REQUIRED"/>  
        <tx:method name="insert*" propagation="REQUIRED"/>  
        <tx:method name="*" read-only="true"/>  
    </tx:attributes>  
</tx:advice>  
  
<aop:config proxy-target-class="true">  
     <aop:pointcut id="allManagerMethod" expression="execution(* pp.business.*.*(..)) or execution(* pp.business.impl.*.*(..))" />  
     <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>  
</aop:config>

關(guān)于“spring aop pointcut怎么添加多個execution”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI