這篇文章主要介紹“Spring Transactional事務(wù)和日志的用法”,在日常操作中,相信很多人在Spring Transactional事務(wù)和日志的用法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Spring Transactional事務(wù)和日志的用法”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、成都網(wǎng)站設(shè)計、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的郟縣網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
1、主要代碼
// 切換數(shù)據(jù)源 @DataSourceRouting // 開始事務(wù) @Transactional(rollbackFor = Exception.class) public boolean test1(Long userId, List<String> labelList) { biz1(userId, labelList); biz2(userId, labelList); return true; } public boolean biz1(Long userId, List<String> labelList) { log.info("》》》》》》》》插入 FamilyPlanLabelDetail 》》》 開始"); FamilyPlanLabelDetail familyPlanLabelDetail = new FamilyPlanLabelDetail(); familyPlanLabelDetail.setUserId(userId); familyPlanLabelDetail.setCreateTime(new Date()); int numLabelDetail = familyPlanDao.saveFamilyPlanLabelDetail(familyPlanLabelDetail); log.info("》》》》》》》》插入 FamilyPlanLabelDetail 》》》 結(jié)束"); return true; } public boolean biz2(Long userId, List<String> labelList) throws Exception { log.info("》》》》》》》》插入 FamilyPlanLabel 》》》 開始"); List<FamilyPlanLabel> list = new ArrayList(); for (String labelName : labelList) { FamilyPlanLabel familyPlanLabel = new FamilyPlanLabel(); familyPlanLabel.setUserId(userId); familyPlanLabel.setLabelName(labelName); familyPlanLabel.setType(FamilyPlanLabelTypeEnum.SYS_ADD.getCode()); familyPlanLabel.setStatus(FamilyPlanLabelStatusEnum.USE.getCode()); familyPlanLabel.setCreateTime(new Date()); familyPlanLabel.setUpdateTime(new Date()); list.add(familyPlanLabel); } int labelNum = familyPlanDao.saveFamilyPlanLabelByBatch(list); if (true) { // 模擬出異常 throw new Exception("手動拋異常"); } log.info("》》》》》》》》插入 FamilyPlanLabel 》》》 結(jié)束"); return true; }
2 開事務(wù)
2.1 開事務(wù),正常的日志
// 方法上有注解 @DataSourceRouting @Transactional com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.client.transaction.manager.FamilyPlanTransactionManager.test1(...)方法執(zhí)行開始執(zhí)行,數(shù)據(jù)源切換到:master com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》查詢 FamilyPlanLabelDetail 》》》 開始 // 因為在事務(wù)中,切換數(shù)據(jù)源并沒有用 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.queryFamilyPlanLabelDetailByUserId(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master // 開啟事務(wù) org.mybatis.spring.SqlSessionUtils Creating a new SqlSession org.mybatis.spring.SqlSessionUtils Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@eeede52] will be managed by Spring com.moon.core.dao.FamilyPlanDao.queryFamilyPlanLabelDetailByUserId ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@eeede52] com.moon.core.dao.FamilyPlanDao.queryFamilyPlanLabelDetailByUserId ==> Preparing: SELECT id, user_id AS userId, create_time AS createTime FROM t_detail WHERE user_id = ? com.moon.core.dao.FamilyPlanDao.queryFamilyPlanLabelDetailByUserId ==> Parameters: 1(Long) org.mybatis.spring.SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.queryFamilyPlanLabelDetailByUserId(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》查詢 FamilyPlanLabelDetail 》》》 結(jié)束 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 開始 // 因為在事務(wù)中,切換數(shù)據(jù)源并沒有用 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] from current transaction com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@eeede52] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Preparing: INSERT INTO t_detail ( user_id, create_time ) VALUES ( ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Parameters: 1(Long), 2019-09-16 12:02:00.075(Timestamp) org.mybatis.spring.SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 結(jié)束 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabel 》》》 開始 // 因為在事務(wù)中,切換數(shù)據(jù)源并沒有用 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] from current transaction com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@eeede52] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Preparing: INSERT INTO t_label ( user_id, label_name, type, status, create_time, update_time ) VALUES ( ?, ?, ?, ?, ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Parameters: 1(Long), test1342966(String), 1(Integer), 1(Integer), 2019-09-16 12:02:00.917(Timestamp), 2019-09-16 12:02:00.917(Timestamp) org.mybatis.spring.SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabel 》》》 結(jié)束 // 提交事務(wù) org.mybatis.spring.SqlSessionUtils Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] org.mybatis.spring.SqlSessionUtils Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@cdf939b] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.client.transaction.manager.FamilyPlanTransactionManager.test1(...)方法執(zhí)行完成,清理數(shù)據(jù)源
注意:
(1)org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3d2fb2bf] will be managed by Spring
(2)org.mybatis.spring.SqlSessionUtils Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@251c52c5]
2.2 開事務(wù),出現(xiàn)異常回滾的日志
com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.client.transaction.manager.FamilyPlanTransactionManager.test1(...)方法執(zhí)行開始執(zhí)行,數(shù)據(jù)源切換到:master com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 開始 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Creating a new SqlSession org.mybatis.spring.SqlSessionUtils Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835] org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3d2fb2bf] will be managed by Spring com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3d2fb2bf] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Preparing: INSERT INTO t_detail ( user_id, create_time ) VALUES ( ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Parameters: 1(Long), 2019-09-16 10:26:50.722(Timestamp) org.mybatis.spring.SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 結(jié)束 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabel 》》》 開始 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835] from current transaction com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3d2fb2bf] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Preparing: INSERT INTO t_label ( user_id, label_name, type, status, create_time, update_time ) VALUES ( ?, ?, ?, ?, ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Parameters: 1(Long), test1591984(String), 1(Integer), 1(Integer), 2019-09-16 10:27:12.847(Timestamp), 2019-09-16 10:27:12.847(Timestamp) org.mybatis.spring.SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行完成,清理數(shù)據(jù)源 org.mybatis.spring.SqlSessionUtils Transaction synchronization rolling back SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835] org.mybatis.spring.SqlSessionUtils Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.client.transaction.manager.FamilyPlanTransactionManager.test1(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.home.controller.AtestController 出現(xiàn)了異常 java.lang.RuntimeException: 家庭計劃,初始化賬戶系統(tǒng)默認賬戶類型.出現(xiàn)異常 at com.moon.client.transaction.manager.FamilyPlanTransactionManager.biz2(FamilyPlanTransactionManager.java:367) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at com.moon.client.transaction.manager.FamilyPlanTransactionManager.test1(FamilyPlanTransactionManager.java:382) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at com.moon.client.transaction.manager.FamilyPlanTransactionManager$$FastClassBySpringCGLIB$$728e76cf.invoke(<generated>) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE]
注意:
(1)org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3d2fb2bf] will be managed by Spring
(2)org.mybatis.spring.SqlSessionUtils Transaction synchronization rolling back SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@67334835]
2.3 開啟事務(wù)總結(jié)
(1)方法上加了@Transactional ,在進入方法的業(yè)務(wù)代碼前(本例就是進入 test1() 的業(yè)務(wù)代碼前)已經(jīng)決定了使用哪個數(shù)據(jù)源,在業(yè)務(wù)方法 biz1()或biz2()內(nèi)切換數(shù)據(jù)源是無效的。
(2) 加了@Transactional注解,如果在進入test1()方法前指定了數(shù)據(jù)源,test1() 沒有在切面中切換數(shù)據(jù)源,則以進入test1()方法前用的數(shù)據(jù)源為準;如果沒有指定數(shù)據(jù)源,以系統(tǒng)配置的默認數(shù)據(jù)源。
(3)并不是加了@Transactional 注解,在進入test1() 方法后就開啟事務(wù),是有SQL執(zhí)行時才會開啟事務(wù)。
3 不開事務(wù)
3.1 不開事務(wù),執(zhí)行成功日志
// 進入 biz1(...)方法 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 開始 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Creating a new SqlSession org.mybatis.spring.SqlSessionUtils SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@57494412] was not registered for synchronization because synchronization is not active org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] will not be managed by Spring com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Preparing: INSERT INTO t_detail ( user_id, create_time ) VALUES ( ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Parameters: 1(Long), 2019-09-17 11:06:00.781(Timestamp) org.mybatis.spring.SqlSessionUtils Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@57494412] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 結(jié)束 // 進入 biz2(...)方法 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabel 》》》 開始 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Creating a new SqlSession org.mybatis.spring.SqlSessionUtils SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5471460] was not registered for synchronization because synchronization is not active org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] will not be managed by Spring com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Preparing: INSERT INTO t_label ( user_id, label_name, type, status, create_time, update_time ) VALUES ( ?, ?, ?, ?, ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Parameters: 1(Long), test1(String), 1(Integer), 1(Integer), 2019-09-17 11:06:01.056(Timestamp), 2019-09-17 11:06:01.056(Timestamp) org.mybatis.spring.SqlSessionUtils Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5471460] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabel 》》》 結(jié)束
3.2 不開事務(wù),拋出異常日志
// 進入 biz1(...)方法 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 開始 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Creating a new SqlSession org.mybatis.spring.SqlSessionUtils SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@65ad141b] was not registered for synchronization because synchronization is not active org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] will not be managed by Spring com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Preparing: INSERT INTO t_detail ( user_id, create_time ) VALUES ( ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail ==> Parameters: 1(Long), 2019-09-17 10:55:05.748(Timestamp) org.mybatis.spring.SqlSessionUtils Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@65ad141b] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelDetail(...)方法執(zhí)行完成,清理數(shù)據(jù)源 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabelDetail 》》》 結(jié)束 // 進入 biz2(...)方法 com.moon.client.transaction.manager.FamilyPlanTransactionManager 》》》》》》》》插入 FamilyPlanLabel 》》》 開始 com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行開始執(zhí)行,沒有配置數(shù)據(jù)源,切換到默認:master org.mybatis.spring.SqlSessionUtils Creating a new SqlSession org.mybatis.spring.SqlSessionUtils SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4d1121df] was not registered for synchronization because synchronization is not active org.mybatis.spring.transaction.SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] will not be managed by Spring com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@320e24b0] com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Preparing: INSERT INTO t_label ( user_id, label_name, type, status, create_time, update_time ) VALUES ( ?, ?, ?, ?, ?, ? ) com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch ==> Parameters: 1(Long), test1(String), 1(Integer), 1(Integer), 2019-09-17 10:55:06.6(Timestamp), 2019-09-17 10:55:06.6(Timestamp) org.mybatis.spring.SqlSessionUtils Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4d1121df] com.moon.core.dbUtils.DataSourceAspect 【數(shù)據(jù)源處理】com.moon.core.dao.FamilyPlanDao.saveFamilyPlanLabelByBatch(...)方法執(zhí)行完成,清理數(shù)據(jù)源 // biz2里的saveFamilyPlanLabelByBatch()方法拋出異常 com.moon.appserver.controller.privates.TestTranController java.lang.Exception: 手動拋異常 at com.moon.client.transaction.manager.FamilyPlanTransactionManager.biz2(FamilyPlanTransactionManager.java:366) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at com.moon.client.transaction.manager.FamilyPlanTransactionManager.test1(FamilyPlanTransactionManager.java:380) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at com.moon.client.transaction.manager.FamilyPlanTransactionManager.test2(FamilyPlanTransactionManager.java:385) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at com.moon.client.transaction.manager.FamilyPlanTransactionManager$$FastClassBySpringCGLIB$$728e76cf.invoke(<generated>) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.11.RELEASE.jar:4.3.11.RELEASE] at com.moon.client.transaction.manager.FamilyPlanTransactionManager$$EnhancerBySpringCGLIB$$d931e707.test2(<generated>) ~[CKclient-1.0.0-SNAPSHOT.jar:na] at com.moon.appserver.controller.privates.TestTranController.test(TestTranController.java:29) ~[classes/:na]
到此,關(guān)于“Spring Transactional事務(wù)和日志的用法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
新聞標題:SpringTransactional事務(wù)和日志的用法
當前鏈接:http://www.rwnh.cn/article38/jjsgpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、域名注冊、動態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計、建站公司、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)