Spring @Transactional的配置替代方案

sim*_*n_d 7 spring transactions

是否有任何基于配置的替代Spring中的@Transactional注释?

我想让我的java类尽可能免于Spring,即尽可能与任何框架分离.

Boz*_*zho 8

是的,使用aop:configtx:advice.例如:

<aop:config>
    <aop:pointcut id="serviceMethods"
        expression="execution(* com.package.service..*.*(..))" />

    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>
Run Code Online (Sandbox Code Playgroud)