想看一下声明式事务的传播机制,但是相关日志是在控制台输出的,找了下关键的类SqlSessionUtils
,并将其配置到Logback日志文件中,这下可以在日志中查看关键逻辑的事务行为。
一、Mybaits控制台输出
### 开启sql日志
mybatis-plus
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
JDBC Connection [HikariProxyConnection@898692052 wrapping com.mysql.jdbc.JDBC4Connection@6a0c5a04] will be managed by Spring
==> Preparing: DELETE FROM user_info WHERE uid in ( ? , ? , ? )
==> Parameters: 44(Long), 45(Long), 46(Long)
<== Updates: 0
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2e943ddb]
二、日志框架输出
### 开启sql日志
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
# log-impl: org.apache.ibatis.logging.log4j.Log4jImpl
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 关闭mybatis plus日志
# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
Logback的配置
<logger name="org.mybatis.spring" level="INFO"/>
<logger name="com.baomidou.dynamic.datasource" level="WARN"/>
<logger name="com.baomidou.mybatisplus" level="INFO"/>
<logger name="com.zaxxer.hikari" level="INFO"/>
<springProfile name="dev">
<!-- 屏蔽IBusLogMapper日志 -->
<logger name="com.demo.dao.IBusLogMapper" level="INFO"/>
<!-- 打开SqlSession事务操作日志 -->
<logger name="org.mybatis.spring.SqlSessionUtils" level="DEBUG"/>
<root level="DEBUG">
<!-- <appender-ref ref="STDOUT"/> -->
</root>
</springProfile>
<springProfile name="test,prod">
<root level="INFO">
<!-- <appender-ref ref="INFO_FILE"/> -->
</root>
</springProfile>