https://zhuanlan.zhihu.com/p/612825647?utm_id=0
https://blog.csdn.net/guzhangyu12345/article/details/108559810
SpringBoot多数据源事务解决方案
https://blog.csdn.net/u013407099/article/details/124526396多数据源切换下保证事务解决方案
https://blog.csdn.net/reee112/article/details/90442542
概述
在大型项目开发中,当数据量达到一定程度后,我们一般采用分库分表来实现数据层的拓展,面对复杂的存储层,相应的数据库中间件和多数据源切换的需求就应运而生。
这里我们重点讨论下多数据源切换,多数据源的动态切换可以方便我们快速的实现主从读写分离、异构纯粹多库等动态数据库操作。
常见的多数据源一般有以下两种解决方案:
1、通过显示模式声明多数据源,应用切换。优点是简单,缺点是不易于拓展,强耦合。
2、通过优先代理类实现动态切换,Spring的AbstractRoutingDataSource就是采用这种架构。
可以基于dynamic-datasource-spring-boot-starter实现动态多数据源切换。
前情提要
多数据源切换流程结构图如下所示,包含几个组成元素:
自定义的数据源配置处理,通过DataSource对象动态注册到系统中
自定义数据源标识注解与切面
数据源切换时的上下文线程变量持有者
自定义AbstractRoutingDataSource,实现数据源路由切换
事务
如果只是重写了AbstractRoutingDataSource方法,那么在事务下数据源是切换不了的,还需要重写事务方法。
Spring使用事务的方式有两种,一种是声明式事务,一种是编程式事务,我们讨论的都是关于声明式事务,这种方式很方便,也是大家常用的,这里为什么讨论这个问题,当我们想将不同库的表放在同一个事务使用的时候会报错。
我们要做就是动态的根据DataSourceType获取不同的Connection,不从缓存中获取Connection。
在Spring事务管理中有一个核心类DataSourceTransactionManager,该类是Spring事务核心的默认实现,AbstractPlatformTransactionManager是整体的Spring事务实现模板类,整体的继承结构如下图。
Mybatis
@DataSourceCurrent("master")
@Mapper
public interface Order1Mapper extends BaseMapper<Order1> {}@DataSourceCurrent("second")
@Mapper
public interface Order2Mapper extends BaseMapper<Order2> {}
公共方法标记@Transactional
@Service
public class OrderServiceImpl implements OrderService {@Resourceprivate Order1Service order1Service;@Resourceprivate Order2Service order2Service;@Transactional@Overridepublic void saveOrders2(){order1Service.updateOrderById();order2Service.updateOrderById(); //set exception, rollback all}
Main方法 @Import
@Import(DynamicDataSourceRegistrar.class)
@SpringBootApplication
public class DataSourceApplication22 {public static void main(String[] args) { SpringApplication.run(DataSourceApplication22.class, args); }
}
执行结果,回滚日志
D:\Java\jdk1.8.0_251\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar=51331:D:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath D:\Java\jdk1.8.0_251\jre\lib\charsets.jar;D:\Java\jdk1.8.0_251\jre\lib\deploy.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\access-bridge-64.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\cldrdata.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\dnsns.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\jaccess.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\jfxrt.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\localedata.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\nashorn.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunec.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunmscapi.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\zipfs.jar;D:\Java\jdk1.8.0_251\jre\lib\javaws.jar;D:\Java\jdk1.8.0_251\jre\lib\jce.jar;D:\Java\jdk1.8.0_251\jre\lib\jfr.jar;D:\Java\jdk1.8.0_251\jre\lib\jfxswt.jar;D:\Java\jdk1.8.0_251\jre\lib\jsse.jar;D:\Java\jdk1.8.0_251\jre\lib\management-agent.jar;D:\Java\jdk1.8.0_251\jre\lib\plugin.jar;D:\Java\jdk1.8.0_251\jre\lib\resources.jar;D:\Java\jdk1.8.0_251\jre\lib\rt.jar;D:\IdeaProjects\test-datasource22\target\classes;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.6.3\spring-boot-starter-web-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter\2.6.3\spring-boot-starter-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot\2.6.3\spring-boot-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.6.3\spring-boot-starter-logging-2.6.3.jar;C:\Users\LENOVO\.m2\repository\ch\qos\logback\logback-classic\1.2.10\logback-classic-1.2.10.jar;C:\Users\LENOVO\.m2\repository\ch\qos\logback\logback-core\1.2.10\logback-core-1.2.10.jar;C:\Users\LENOVO\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.1\log4j-to-slf4j-2.17.1.jar;C:\Users\LENOVO\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.1\log4j-api-2.17.1.jar;C:\Users\LENOVO\.m2\repository\org\slf4j\jul-to-slf4j\1.7.33\jul-to-slf4j-1.7.33.jar;C:\Users\LENOVO\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-core\5.3.15\spring-core-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-jcl\5.3.15\spring-jcl-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\yaml\snakeyaml\1.29\snakeyaml-1.29.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.6.3\spring-boot-starter-json-2.6.3.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.1\jackson-databind-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.1\jackson-annotations-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.1\jackson-core-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.1\jackson-datatype-jdk8-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.1\jackson-datatype-jsr310-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.1\jackson-module-parameter-names-2.13.1.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.6.3\spring-boot-starter-tomcat-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.56\tomcat-embed-core-9.0.56.jar;C:\Users\LENOVO\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.56\tomcat-embed-el-9.0.56.jar;C:\Users\LENOVO\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.56\tomcat-embed-websocket-9.0.56.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-web\5.3.15\spring-web-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-beans\5.3.15\spring-beans-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-webmvc\5.3.15\spring-webmvc-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-context\5.3.15\spring-context-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-expression\5.3.15\spring-expression-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.6.3\spring-boot-starter-aop-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-aop\5.3.15\spring-aop-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\aspectj\aspectjweaver\1.9.7\aspectjweaver-1.9.7.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-boot-starter\3.3.2\mybatis-plus-boot-starter-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus\3.3.2\mybatis-plus-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-extension\3.3.2\mybatis-plus-extension-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-core\3.3.2\mybatis-plus-core-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-annotation\3.3.2\mybatis-plus-annotation-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\github\jsqlparser\jsqlparser\3.1\jsqlparser-3.1.jar;C:\Users\LENOVO\.m2\repository\org\mybatis\mybatis\3.5.4\mybatis-3.5.4.jar;C:\Users\LENOVO\.m2\repository\org\mybatis\mybatis-spring\2.0.4\mybatis-spring-2.0.4.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.6.3\spring-boot-autoconfigure-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.6.3\spring-boot-starter-jdbc-2.6.3.jar;C:\Users\LENOVO\.m2\repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;C:\Users\LENOVO\.m2\repository\org\slf4j\slf4j-api\1.7.33\slf4j-api-1.7.33.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-jdbc\5.3.15\spring-jdbc-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-tx\5.3.15\spring-tx-5.3.15.jar;C:\Users\LENOVO\.m2\repository\mysql\mysql-connector-java\8.0.28\mysql-connector-java-8.0.28.jar;C:\Users\LENOVO\.m2\repository\com\alibaba\fastjson\1.2.83\fastjson-1.2.83.jar;C:\Users\LENOVO\.m2\repository\org\projectlombok\lombok\1.18.22\lombok-1.18.22.jar com.java.DataSourceApplication22. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v2.6.3)2024-03-10 17:41:56.342 INFO 30476 --- [ main] com.java.DataSourceApplication22 : Starting DataSourceApplication22 using Java 1.8.0_251 on DESKTOP-GCE7E0L with PID 30476 (D:\IdeaProjects\test-datasource22\target\classes started by LENOVO in D:\IdeaProjects\test-datasource22)
2024-03-10 17:41:56.346 INFO 30476 --- [ main] com.java.DataSourceApplication22 : The following profiles are active: test
2024-03-10 17:41:56.759 INFO 30476 --- [ main] c.j.config.DynamicDataSourceRegistrar : 开始注册数据源 evn
2024-03-10 17:41:57.236 INFO 30476 --- [ main] c.j.config.DynamicDataSourceRegistrar : register, bind ds: master, second ---- registerBeanDefinitions()
2024-03-10 17:41:57.246 INFO 30476 --- [ main] com.zaxxer.hikari.HikariDataSource : master - Starting...
2024-03-10 17:41:57.437 INFO 30476 --- [ main] com.zaxxer.hikari.HikariDataSource : master - Start completed.
2024-03-10 17:41:57.442 INFO 30476 --- [ main] c.j.config.DynamicDataSourceRegistrar : ==================注册数据源master成功
2024-03-10 17:41:57.442 INFO 30476 --- [ main] com.zaxxer.hikari.HikariDataSource : second - Starting...
2024-03-10 17:41:57.454 INFO 30476 --- [ main] com.zaxxer.hikari.HikariDataSource : second - Start completed.
2024-03-10 17:41:57.454 INFO 30476 --- [ main] c.j.config.DynamicDataSourceRegistrar : ==========注册数据源second成功
2024-03-10 17:41:57.457 INFO 30476 --- [ main] c.j.config.DynamicDataSourceRegistrar : 注册数据源成功,一共注册2个数据源
2024-03-10 17:41:58.781 INFO 30476 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8099 (http)
2024-03-10 17:41:58.792 INFO 30476 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-03-10 17:41:58.793 INFO 30476 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2024-03-10 17:41:58.951 INFO 30476 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-03-10 17:41:58.951 INFO 30476 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2522 ms
dynamic ds classpath:mapper/*.xml_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\ / | 3.3.2
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2024-03-10 17:42:01.556 INFO 30476 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8099 (http) with context path ''
2024-03-10 17:42:01.570 INFO 30476 --- [ main] com.java.DataSourceApplication22 : Started DataSourceApplication22 in 6.208 seconds (JVM running for 8.211)
2024-03-10 17:42:22.205 INFO 30476 --- [nio-8099-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-03-10 17:42:22.205 INFO 30476 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2024-03-10 17:42:22.207 INFO 30476 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2024-03-10 17:42:22.260 INFO 30476 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2024-03-10 17:42:22.272 INFO 30476 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2024-03-10 17:42:22.292 INFO 30476 --- [nio-8099-exec-1] com.java.service.OrderServiceImpl : update start......
2024-03-10 17:42:22.308 INFO 30476 --- [nio-8099-exec-1] com.java.service.Order1ServiceImpl : update order1 start...
2024-03-10 17:42:22.320 INFO 30476 --- [nio-8099-exec-1] com.java.config.DsMapperAspect1 : MapperAspect set 数据源: master
2024-03-10 17:42:22.321 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, set ds key:master
Creating a new SqlSession
================init MultiDataSourceTransaction Factory================
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2eaf1022]
2024-03-10 17:42:22.404 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:master
2024-03-10 17:42:22.405 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds map, dsName:master
2024-03-10 17:42:22.405 INFO 30476 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, get conn, ThreadLocal----null
2024-03-10 17:42:22.405 ERROR 30476 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds get conn, ds key null, 没开事务
2024-03-10 17:42:22.405 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:master
2024-03-10 17:42:22.405 INFO 30476 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, determineCurrentLookupKey 当前数据源: master
2024-03-10 17:42:22.406 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds, conn: HikariProxyConnection@198635215 wrapping com.mysql.cj.jdbc.ConnectionImpl@49b6b5eb
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2eaf1022]
2024-03-10 17:42:22.464 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, rm key:master
2024-03-10 17:42:22.465 INFO 30476 --- [nio-8099-exec-1] com.java.service.Order1ServiceImpl : ---update order1 OK, result:1
2024-03-10 17:42:22.466 INFO 30476 --- [nio-8099-exec-1] com.java.service.OrderServiceImpl : ======================================
2024-03-10 17:42:22.479 INFO 30476 --- [nio-8099-exec-1] com.java.service.Order2ServiceImpl : ---update order2 start...
2024-03-10 17:42:22.481 INFO 30476 --- [nio-8099-exec-1] com.java.config.DsMapperAspect1 : MapperAspect set 数据源: second
2024-03-10 17:42:22.481 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, set ds key:second
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2eaf1022] from current transaction
2024-03-10 17:42:22.483 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:second
2024-03-10 17:42:22.483 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds map, dsName:second
2024-03-10 17:42:22.483 INFO 30476 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, get conn, ThreadLocal----null
2024-03-10 17:42:22.483 ERROR 30476 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds get conn, ds key null, 没开事务
2024-03-10 17:42:22.483 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:second
2024-03-10 17:42:22.483 INFO 30476 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, determineCurrentLookupKey 当前数据源: second
2024-03-10 17:42:22.484 INFO 30476 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Starting...
2024-03-10 17:42:22.493 INFO 30476 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Start completed.
2024-03-10 17:42:22.494 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds, conn: HikariProxyConnection@21529602 wrapping com.mysql.cj.jdbc.ConnectionImpl@16746d16
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2eaf1022]
2024-03-10 17:42:22.499 INFO 30476 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, rm key:second
2024-03-10 17:42:22.500 INFO 30476 --- [nio-8099-exec-1] com.java.service.Order2ServiceImpl : ---update order2 OK, result:1
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2eaf1022]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2eaf1022]
2024-03-10 17:42:22.502 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, do rollback
2024-03-10 17:42:22.515 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, do rollback
2024-03-10 17:42:22.520 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, connection close
2024-03-10 17:42:22.527 INFO 30476 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, connection close
2024-03-10 17:42:22.555 ERROR 30476 --- [nio-8099-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: order2 exception] with root causejava.lang.RuntimeException: order2 exceptionat com.java.service.Order2ServiceImpl.updateOrderById(Order2ServiceImpl.java:33) ~[classes/:na]at com.java.service.Order2ServiceImpl$$FastClassBySpringCGLIB$$31f65359.invoke(<generated>) ~[classes/:na]at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.15.jar:5.3.15]at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.3.15.jar:5.3.15]at com.java.service.Order2ServiceImpl$$EnhancerBySpringCGLIB$$abbb8a2e.updateOrderById(<generated>) ~[classes/:na]at com.java.service.OrderServiceImpl.saveOrders2(OrderServiceImpl.java:62) ~[classes/:na]at com.java.service.OrderServiceImpl$$FastClassBySpringCGLIB$$f72571f.invoke(<generated>) ~[classes/:na]at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.15.jar:5.3.15]at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783) ~[spring-aop-5.3.15.jar:5.3.15]at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.15.jar:5.3.15]at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) ~[spring-aop-5.3.15.jar:5.3.15]at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.15.jar:5.3.15]at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.15.jar:5.3.15]at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.15.jar:5.3.15]at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.15.jar:5.3.15]at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) ~[spring-aop-5.3.15.jar:5.3.15]at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698) ~[spring-aop-5.3.15.jar:5.3.15]at com.java.service.OrderServiceImpl$$EnhancerBySpringCGLIB$$8e952140.saveOrders2(<generated>) ~[classes/:na]at com.java.controller.OrderController.saveOrder2(OrderController.java:34) ~[classes/:na]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.15.jar:5.3.15]at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.15.jar:5.3.15]at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.15.jar:5.3.15]at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.15.jar:5.3.15]at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.56.jar:4.0.FR]at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.15.jar:5.3.15]at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.56.jar:4.0.FR]at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.56.jar:9.0.56]at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.15.jar:5.3.15]at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.15.jar:5.3.15]at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.15.jar:5.3.15]at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1732) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.56.jar:9.0.56]at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.56.jar:9.0.56]at java.lang.Thread.run(Thread.java:748) [na:1.8.0_251]
执行成功日志
D:\Java\jdk1.8.0_251\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar=51430:D:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath D:\Java\jdk1.8.0_251\jre\lib\charsets.jar;D:\Java\jdk1.8.0_251\jre\lib\deploy.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\access-bridge-64.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\cldrdata.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\dnsns.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\jaccess.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\jfxrt.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\localedata.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\nashorn.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunec.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunmscapi.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk1.8.0_251\jre\lib\ext\zipfs.jar;D:\Java\jdk1.8.0_251\jre\lib\javaws.jar;D:\Java\jdk1.8.0_251\jre\lib\jce.jar;D:\Java\jdk1.8.0_251\jre\lib\jfr.jar;D:\Java\jdk1.8.0_251\jre\lib\jfxswt.jar;D:\Java\jdk1.8.0_251\jre\lib\jsse.jar;D:\Java\jdk1.8.0_251\jre\lib\management-agent.jar;D:\Java\jdk1.8.0_251\jre\lib\plugin.jar;D:\Java\jdk1.8.0_251\jre\lib\resources.jar;D:\Java\jdk1.8.0_251\jre\lib\rt.jar;D:\IdeaProjects\test-datasource22\target\classes;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.6.3\spring-boot-starter-web-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter\2.6.3\spring-boot-starter-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot\2.6.3\spring-boot-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.6.3\spring-boot-starter-logging-2.6.3.jar;C:\Users\LENOVO\.m2\repository\ch\qos\logback\logback-classic\1.2.10\logback-classic-1.2.10.jar;C:\Users\LENOVO\.m2\repository\ch\qos\logback\logback-core\1.2.10\logback-core-1.2.10.jar;C:\Users\LENOVO\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.1\log4j-to-slf4j-2.17.1.jar;C:\Users\LENOVO\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.1\log4j-api-2.17.1.jar;C:\Users\LENOVO\.m2\repository\org\slf4j\jul-to-slf4j\1.7.33\jul-to-slf4j-1.7.33.jar;C:\Users\LENOVO\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-core\5.3.15\spring-core-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-jcl\5.3.15\spring-jcl-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\yaml\snakeyaml\1.29\snakeyaml-1.29.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.6.3\spring-boot-starter-json-2.6.3.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.1\jackson-databind-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.1\jackson-annotations-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.1\jackson-core-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.1\jackson-datatype-jdk8-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.1\jackson-datatype-jsr310-2.13.1.jar;C:\Users\LENOVO\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.1\jackson-module-parameter-names-2.13.1.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.6.3\spring-boot-starter-tomcat-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.56\tomcat-embed-core-9.0.56.jar;C:\Users\LENOVO\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.56\tomcat-embed-el-9.0.56.jar;C:\Users\LENOVO\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.56\tomcat-embed-websocket-9.0.56.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-web\5.3.15\spring-web-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-beans\5.3.15\spring-beans-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-webmvc\5.3.15\spring-webmvc-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-context\5.3.15\spring-context-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-expression\5.3.15\spring-expression-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.6.3\spring-boot-starter-aop-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-aop\5.3.15\spring-aop-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\aspectj\aspectjweaver\1.9.7\aspectjweaver-1.9.7.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-boot-starter\3.3.2\mybatis-plus-boot-starter-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus\3.3.2\mybatis-plus-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-extension\3.3.2\mybatis-plus-extension-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-core\3.3.2\mybatis-plus-core-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\baomidou\mybatis-plus-annotation\3.3.2\mybatis-plus-annotation-3.3.2.jar;C:\Users\LENOVO\.m2\repository\com\github\jsqlparser\jsqlparser\3.1\jsqlparser-3.1.jar;C:\Users\LENOVO\.m2\repository\org\mybatis\mybatis\3.5.4\mybatis-3.5.4.jar;C:\Users\LENOVO\.m2\repository\org\mybatis\mybatis-spring\2.0.4\mybatis-spring-2.0.4.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.6.3\spring-boot-autoconfigure-2.6.3.jar;C:\Users\LENOVO\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.6.3\spring-boot-starter-jdbc-2.6.3.jar;C:\Users\LENOVO\.m2\repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;C:\Users\LENOVO\.m2\repository\org\slf4j\slf4j-api\1.7.33\slf4j-api-1.7.33.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-jdbc\5.3.15\spring-jdbc-5.3.15.jar;C:\Users\LENOVO\.m2\repository\org\springframework\spring-tx\5.3.15\spring-tx-5.3.15.jar;C:\Users\LENOVO\.m2\repository\mysql\mysql-connector-java\8.0.28\mysql-connector-java-8.0.28.jar;C:\Users\LENOVO\.m2\repository\com\alibaba\fastjson\1.2.83\fastjson-1.2.83.jar;C:\Users\LENOVO\.m2\repository\org\projectlombok\lombok\1.18.22\lombok-1.18.22.jar com.java.DataSourceApplication22. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v2.6.3)2024-03-10 17:42:54.409 INFO 21316 --- [ main] com.java.DataSourceApplication22 : Starting DataSourceApplication22 using Java 1.8.0_251 on DESKTOP-GCE7E0L with PID 21316 (D:\IdeaProjects\test-datasource22\target\classes started by LENOVO in D:\IdeaProjects\test-datasource22)
2024-03-10 17:42:54.416 INFO 21316 --- [ main] com.java.DataSourceApplication22 : The following profiles are active: test
2024-03-10 17:42:55.127 INFO 21316 --- [ main] c.j.config.DynamicDataSourceRegistrar : 开始注册数据源 evn
2024-03-10 17:42:56.095 INFO 21316 --- [ main] c.j.config.DynamicDataSourceRegistrar : register, bind ds: master, second ---- registerBeanDefinitions()
2024-03-10 17:42:56.109 INFO 21316 --- [ main] com.zaxxer.hikari.HikariDataSource : master - Starting...
2024-03-10 17:42:56.512 INFO 21316 --- [ main] com.zaxxer.hikari.HikariDataSource : master - Start completed.
2024-03-10 17:42:56.518 INFO 21316 --- [ main] c.j.config.DynamicDataSourceRegistrar : ==================注册数据源master成功
2024-03-10 17:42:56.519 INFO 21316 --- [ main] com.zaxxer.hikari.HikariDataSource : second - Starting...
2024-03-10 17:42:56.538 INFO 21316 --- [ main] com.zaxxer.hikari.HikariDataSource : second - Start completed.
2024-03-10 17:42:56.538 INFO 21316 --- [ main] c.j.config.DynamicDataSourceRegistrar : ==========注册数据源second成功
2024-03-10 17:42:56.543 INFO 21316 --- [ main] c.j.config.DynamicDataSourceRegistrar : 注册数据源成功,一共注册2个数据源
2024-03-10 17:42:58.425 INFO 21316 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8099 (http)
2024-03-10 17:42:58.445 INFO 21316 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-03-10 17:42:58.446 INFO 21316 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2024-03-10 17:42:58.664 INFO 21316 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-03-10 17:42:58.664 INFO 21316 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4109 ms
dynamic ds classpath:mapper/*.xml_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\ / | 3.3.2
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2024-03-10 17:43:01.646 INFO 21316 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8099 (http) with context path ''
2024-03-10 17:43:01.666 INFO 21316 --- [ main] com.java.DataSourceApplication22 : Started DataSourceApplication22 in 8.584 seconds (JVM running for 11.011)
2024-03-10 17:45:11.727 INFO 21316 --- [nio-8099-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-03-10 17:45:11.727 INFO 21316 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2024-03-10 17:45:11.730 INFO 21316 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2024-03-10 17:45:11.781 INFO 21316 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2024-03-10 17:45:11.789 INFO 21316 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2024-03-10 17:45:11.805 INFO 21316 --- [nio-8099-exec-1] com.java.service.OrderServiceImpl : update start......
2024-03-10 17:45:11.820 INFO 21316 --- [nio-8099-exec-1] com.java.service.Order1ServiceImpl : update order1 start...
2024-03-10 17:45:11.831 INFO 21316 --- [nio-8099-exec-1] com.java.config.DsMapperAspect1 : MapperAspect set 数据源: master
2024-03-10 17:45:11.833 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, set ds key:master
Creating a new SqlSession
================init MultiDataSourceTransaction Factory================
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f]
2024-03-10 17:45:11.905 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:master
2024-03-10 17:45:11.905 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds map, dsName:master
2024-03-10 17:45:11.905 INFO 21316 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, get conn, ThreadLocal----null
2024-03-10 17:45:11.905 ERROR 21316 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds get conn, ds key null, 没开事务
2024-03-10 17:45:11.906 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:master
2024-03-10 17:45:11.906 INFO 21316 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, determineCurrentLookupKey 当前数据源: master
2024-03-10 17:45:11.906 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds, conn: HikariProxyConnection@1000277724 wrapping com.mysql.cj.jdbc.ConnectionImpl@4bc1686c
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f]
2024-03-10 17:45:11.963 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, rm key:master
2024-03-10 17:45:11.963 INFO 21316 --- [nio-8099-exec-1] com.java.service.Order1ServiceImpl : ---update order1 OK, result:1
2024-03-10 17:45:11.963 INFO 21316 --- [nio-8099-exec-1] com.java.service.OrderServiceImpl : ======================================
2024-03-10 17:45:11.977 INFO 21316 --- [nio-8099-exec-1] com.java.service.Order2ServiceImpl : ---update order2 start...
2024-03-10 17:45:11.978 INFO 21316 --- [nio-8099-exec-1] com.java.config.DsMapperAspect1 : MapperAspect set 数据源: second
2024-03-10 17:45:11.978 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, set ds key:second
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f] from current transaction
2024-03-10 17:45:11.980 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:second
2024-03-10 17:45:11.980 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds map, dsName:second
2024-03-10 17:45:11.980 INFO 21316 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, get conn, ThreadLocal----null
2024-03-10 17:45:11.980 ERROR 21316 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds get conn, ds key null, 没开事务
2024-03-10 17:45:11.980 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, get ds key:second
2024-03-10 17:45:11.980 INFO 21316 --- [nio-8099-exec-1] com.java.config.DynamicDataSourceRt : ds, determineCurrentLookupKey 当前数据源: second
2024-03-10 17:45:11.980 INFO 21316 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Starting...
2024-03-10 17:45:11.995 INFO 21316 --- [nio-8099-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Start completed.
2024-03-10 17:45:11.995 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, getConn from ds, conn: HikariProxyConnection@2121567456 wrapping com.mysql.cj.jdbc.ConnectionImpl@76efda58
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f]
2024-03-10 17:45:11.999 INFO 21316 --- [nio-8099-exec-1] com.java.config.DataSourceContextHolder : context, rm key:second
2024-03-10 17:45:12.000 INFO 21316 --- [nio-8099-exec-1] com.java.service.Order2ServiceImpl : ---update order2 OK, result:1
2024-03-10 17:45:12.000 INFO 21316 --- [nio-8099-exec-1] com.java.service.OrderServiceImpl : update order1 order2, END......
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f]
2024-03-10 17:45:12.001 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, commit ----- autoCommit: false
2024-03-10 17:45:12.004 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, commit ----- autoCommit: false
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@28025c1f]
2024-03-10 17:45:12.012 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, connection close
2024-03-10 17:45:12.020 INFO 21316 --- [nio-8099-exec-1] c.j.config.MultiDataSourceTransaction : trans, connection close