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

Spring事务

发布了182 篇原创文章 · 获赞 42 · 访问量 59万+

猜你喜欢

转载自blog.csdn.net/wyyl1/article/details/81288663