1、配置事务注解驱动、每个数据源对应的事务管理器,并定义“限定符”
<tx:annotation-driven/>
<bean id="transactionManager1" class="org.springframework.jdbc.DataSourceTransactionManager">
...
<qualifier value="order"/>
</bean>
<bean id="transactionManager2" class="org.springframework.jdbc.DataSourceTransactionManager">
...
<qualifier value="account"/>
</bean>
2、在需要事务的地方,指定“限定符”
public class TransactionalService {
@Transactional("order")
public void setSomething(String name) { ... }
@Transactional("account")
public void doSomething() { ... }
}
3、如果不指定“限定符”,将默认使用“transationManager”命名对应的事务管理器
The default <tx:annotation-driven> target bean name transactionManager will still be used if
no specifically qualified PlatformTransactionManager bean is found