Mysql + Spring事务资料整理
Mysql
查看存储引擎
可提供的引擎列表
show engines;
当前默认存储引擎
show variables like ‘%storage_engine%’;
查看某个表用了什么引擎
show create table 表名;
查看及设置事物隔离级别
SELECT @@tx_isolation
级别说明
事务隔离级别 | 脏读 | 不可重读 | 幻读 |
---|---|---|---|
读取未提交内容(read-uncommitted) | 是 | 是 | 是 |
读取提交内容(read-committed) | 否 | 是 | 是 |
可重读(repeatable-read) | 否 | 否 | 是 |
串行化(serializable) | 否 | 否 | 否 |
设置mysql的隔离级别
set session transaction isolation level
可供更改的level : READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE
Spring
使用aop进行事务拦截,这样可以在代码中不使用@Transactional注解
<aop:config>
<aop:pointcut id="appService" expression="(execution(* com.aoeai.test..*Service*.* (..)))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="appService"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="select*" propagation="REQUIRED" read-only="true"/>
<tx:method name="find*" propagation="REQUIRED" read-only="true"/>
<tx:method name="get*" propagation="REQUIRED" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
资料来源
Mysql
- https://www.cnblogs.com/xiaohongxin/p/6752831.html
- https://www.cnblogs.com/huanongying/p/7021555.html
- https://zhidao.baidu.com/question/574922372.html