2012-08-30 114 views
4

假設我有一個在類或方法級別標記爲@Transactional的Spring bean,並且在某些使用<aop:config>添加事務性建議的Spring XML中也有。我認爲這兩個配置可以很好地結合在一起,但是當Spring創建它的上下文和代理時,如果配置不兼容(例如PROPAGATION_MANDATORY和PROPAGATION_NEVER),那麼哪個配置具有資歷?春季交易配置 - XML +註釋一起 - 這是高級?

+1

http://stackoverflow.com/questions/1991144/annotation-based-and-xml-based-transaction-definitions-precedence可能的欺騙,但它需要檢查春季3.0+ –

+0

感謝這個。那另外一個問題確實包含我之後的答案! – Stewart

回答

2

要重複的問題作出明確的回答,您可以使用:

<tx:annotation-driven transaction-manager="txManager" order="X"/> 

    <tx:advice id="txAdvice" transaction-manager="txManager"> 

    <aop:config> 
      <aop:pointcut id="pointcut" expression="..."/> 
      <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" order="Y"/> 
    </aop:config> 

...其中 'X' 和 'Y' 的具有優先權。

Spring Docs on the subject