spring?aop?pointcut?添加多個(gè)execution方式
spring aop pointcut 添加多個(gè)execution
spring aop添加多個(gè)包,用||或者or隔開
<!-- 只對(duì)業(yè)務(wù)邏輯層實(shí)施事務(wù) --> <aop:config expose-proxy="true"> <aop:pointcut expression="execution(* demo.ssh.daoImpl.*.*(..)) || execution(* demo.mes.daoImpl.*.*(..))" id="txPointcut" /> <!-- Advisor定義,切入點(diǎn)和通知分別為txPointcut、txAdvice --> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" /> </aop:config>
spring aop:pointcut--expression--多個(gè)execution連接
聲明式事務(wù),多個(gè)execution連接方法:
expression="execution(* pp.business.*.*(..)) or execution(* pp.business.impl.*.*(..))"
spring的幫助手冊(cè)里有關(guān)于execution的連接方式的一句話:
Pointcut expressions can be combined using '&&', '||' and '!'.
但是我寫上&&就會(huì)報(bào)錯(cuò)。很郁悶。。。
||和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>
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java的@Transactional、@Aysnc、事務(wù)同步問題詳解
這篇文章主要介紹了Java的@Transactional、@Aysnc、事務(wù)同步問題詳解,現(xiàn)在我們需要在一個(gè)業(yè)務(wù)方法中插入一個(gè)用戶,這個(gè)業(yè)務(wù)方法我們需要加上事務(wù),然后插入用戶后,我們要異步的方式打印出數(shù)據(jù)庫中所有存在的用戶,需要的朋友可以參考下2023-11-11Mybatis調(diào)用Oracle存儲(chǔ)過程的方法圖文詳解
這篇文章主要介紹了Mybatis調(diào)用Oracle存儲(chǔ)過程的方法介紹,需要的朋友可以參考下2017-09-09mybatis框架之mybatis中dao層開發(fā)的兩種方法
這篇文章主要介紹了mybatis框架之mybatis中dao層開發(fā)的兩種方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07詳解MyBatis中主鍵回填的兩種實(shí)現(xiàn)方式
這篇文章主要介紹了詳解MyBatis中主鍵回填的兩種實(shí)現(xiàn)方式,主鍵回填其實(shí)是一個(gè)非常常見的需求,特別是在數(shù)據(jù)添加的過程中,我們經(jīng)常需要添加完數(shù)據(jù)之后,需要獲取剛剛添加的數(shù)據(jù) id,有興趣的可以參考一下2019-04-04