Spring @Transactional注解不生效

Spring @Transactional注解不生效

在spring mvc + mysql的项目中,使用Transactional的时候不回滚。

在方法上加的是@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)

  1. 首先先检查了mysql的存储引擎是Innodb,支持事务的
  2. 然后不生效的原因可能就是配置不对了。查了Spring的官方文档之后,可以看到

    You can omit the transaction-manager attribute in the tag if the bean name of the PlatformTransactionManager that you want to wire in has the name transactionManager. If the PlatformTransactionManager bean that you want to dependency-inject has any other name, then you have to use the transaction-manager attribute explicitly, as in the preceding example.

    The @EnableTransactionManagement annotation provides equivalent support if you are using Java based configuration. Simply add the annotation to a @Configuration class. See the javadocs for full details.

    需要配置<tx:annotation-driven />元素或者使用java配置@EnableTransactionManagement

spring boot中已经自动配置,自动配置的类是DataSourceTransactionManagerAutoConfiguration

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值