XML新增声明式事务配置

<!-- 事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 开启事务注解驱动 -->
    <tx:annotation-driven />

 

Service方法使用@Transactional标注:

@Transactional
    public void changeAge(String fromUser, String toUser, int age) {
        testDao.addAge(fromUser, age);

        int a = 1 / 0;

        testDao.addAge(toUser, 0 - age);

    }

 

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2021-10-04
  • 2021-11-06
  • 2021-12-04
  • 2020-01-18
  • 2021-07-07
  • 2022-12-23
猜你喜欢
  • 2022-01-28
  • 2021-04-21
  • 2022-01-03
  • 2022-12-23
  • 2022-01-01
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案