2012-08-30 110 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