SpringBoot多数据源切换 多数据源事务解决方案 二

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/275403.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

谈谈Darknet53为啥这么难训练

在我使用Imagenet2012对Darknet53进行预训练的时候&#xff0c;往往训练到一半&#xff0c;就会出现过拟合&#xff0c;导致无法继续向下训练&#xff0c;尝试了很多方法&#xff0c;最后发现问题出现在下图红框的部分。 得出这个结论是因为当我使用Resnet中&#xff0c;包含有…

Ypay源支付6.9无授权聚合免签系统可运营源码

YPay是一款专为个人站长设计的聚合免签系统&#xff0c;YPay基于高性能的ThinkPHP 6.1.2 Layui PearAdmin架构&#xff0c;提供了实时监控和管理的功能&#xff0c;让您随时随地掌握系统运营情况。 说明 Ypay源支付6.9无授权聚合免签系统可运营源码 已搭建测试无加密版本…

【快速上手ProtoBuf】proto 3 语法详解

1 &#x1f351;字段规则&#x1f351; 消息的字段可以⽤下⾯⼏种规则来修饰&#xff1a; singular &#xff1a;消息中可以包含该字段零次或⼀次&#xff08;不超过⼀次&#xff09;。 proto3 语法中&#xff0c;字段默认使⽤该规则。repeated &#xff1a;消息中可以包含该…

Python中的类【详谈】

零.前言&#xff1a; 本文适合对Python有浅浅了解的读者&#xff0c;并不能作为Python入门使用。 一.Python中类的属性、方法 在Python中有变量&#xff0c;有函数&#xff0c;例如下方&#xff1a; def IAmAFunction():print("I am a function")IAmVariable 25…

iOS 判断触摸位置是否在图片的透明区域

装扮功能系列&#xff1a; Swift 使用UIScrollerView 实现装扮功能&#xff08;基础&#xff09;Swift 使用UIScrollerView 实现装扮功能&#xff08;拓展&#xff09;iOS 判断触摸位置是否在图片的透明区域 背景 在装扮功能中&#xff0c;一般都是长按使道具进入编辑状态&…

【Java设计模式】十九、中介者模式

文章目录 1、中介者模式2、案例3、总结 1、中介者模式 如图&#xff1a; 同事类之间关联较多时&#xff0c;整体出现网状结构&#xff0c;耦合度极高。一个对象一变动&#xff0c;好多对象都得改。若变为右边的星形结构&#xff0c;则一个类的变动&#xff0c;只影响自身与中介…

记录一下在Pycharm中虚拟环境的创建

如果在Pycharm中要新建一个虚拟环境&#xff0c;那你可以在Terminal中选择Command Prompt&#xff0c;在这里面执行相关命令 一、安装了Anaconda&#xff0c;创建虚拟环境 当你使用解释器是Anaconda提供的时&#xff0c;你可以使用conda命令执行&#xff0c;见以下操作&#x…

05-ESP32-S3-IDF USART

ESP32-S3 IDF USART详解 USART简介 USART是一种串行通信协议&#xff0c;广泛应用于微控制器和计算机之间的通信。USART支持异步和同步模式&#xff0c;因此它可以在没有时钟信号的情况下&#xff08;异步模式&#xff09;或有时钟信号的情况下&#xff08;同步模式&#xff…

SQLiteC/C++接口详细介绍之sqlite3类(五)

快速跳转文章列表&#xff1a;SQLite—系列文章目录 上一篇&#xff1a;SQLiteC/C接口详细介绍之sqlite3类&#xff08;四&#xff09; 下一篇&#xff1a;SQLiteC/C接口详细介绍之sqlite3类&#xff08;六&#xff09;&#xff08;未发表&#xff09; 14.sqlite3_busy_handle…

STM32输入捕获频率和占空比proteus仿真失败

这次用了两天的时间来验证这个功能&#xff0c;虽然实验没有成功&#xff0c;但是也要记录一下&#xff0c;后面能解决了&#xff0c;回来再写上解决的办法&#xff1a; 这个程序最后的实验结果是读取到的CCR1和CCR2的值都是0&#xff0c;所以没有办法算出来频率和占空比。 还…

STM32平替GD32有多方便

众所周知, GD32一直模仿STM32,从未被超越。 我最近公司使用的GD32E230C6T6 这款芯片有48个引脚。 属于小容量的芯片。 我有一个用STM32写的代码,之前是用的 STM32F103CB 这款芯片是中容量的。 不过在keil中,只需要这两步,就能使用原来的逻辑,几乎不用修改代码。 1. …

关于分布式微服务数据源加密配置以及取巧方案(含自定义加密配置)

文章目录 前言Spring Cloud 第一代1、创建config server项目并加入加解密key2、启动项目&#xff0c;进行数据加密3、实际项目中的测试server Spring Cloud Alibaba低版本架构不支持&#xff0c;取巧实现无加密配置&#xff0c;联调环境问题加密数据源配置原理探究自定义加密解…

Java学习笔记(11)

面向对象进阶 Static 静态变量 所有对象一起共享&#xff0c;就用static修饰 不属于对象&#xff0c;属于类的 可以用 类名.静态变量 “”&#xff1b;赋值 但是 对象.静态变量也可以访问到内容 Static内存图 Student这个类的字节码文件加载到方法区&#xff0c;并在内…

【C语言】Windows下的C语言线程编程详解

文章目录 1. 头文件1.1 windows.h1.2 process.h 2. 创建线程3. 线程同步3.1 线程同步方式3.1 互斥量&#xff08;Mutex&#xff09;3.2 事件&#xff08;Event&#xff09; 4. 线程的结束与资源管理5.线程池&#xff08;简要&#xff09; 在Windows平台下&#xff0c;C语言提供…

如何“使用Docker快速安装Jenkins,在CentOS7”?

1、运行 docker run -d --namejenkins -p 8080:8080 jenkins/jenkins 2、查看日志 &#xff0c;使用 "docker logs -f jenkins",可以持续刷新日志 docker logs jenkins 3、通过命令查看密码 docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminP…

VUE内盘期货配资软件源码国际外盘二合一

开发一个Vue内盘期货配资软件源码&#xff0c;同时兼容国际外盘二合一的功能&#xff0c;是一个复杂且专业的任务&#xff0c;涉及前端Vue.js框架的使用、后端服务器处理、数据库管理、实时交易接口对接等多个方面。下面是一些关于开发此类软件的基本指导和考虑因素&#xff1a…

FFmpeg工作流程及视频文件分析

FFmpeg工作流程: 解封装(Demuxing)--->解码(Decoding)--->编码(Encoding)--->封装(Muxing) FFmpeg转码工作流程: 读取输入流--->音视频解封装--->解码音视频帧--->编码音视频帧--->音视频封装--->输出目标流 可简单理解为如下流程: 读文件-->解…

程序员的三重境界:码农,高级码农、程序员!

见字如面&#xff0c;我是军哥&#xff01; 掐指一算&#xff0c;我在 IT 行业摸爬滚打 19 年了&#xff0c;见过的程序员至少大好几千&#xff0c;然后真正能称上程序员不到 10% &#xff0c;绝大部分都是高级码农而已。 今天和你聊聊程序员的三个境界的差异&#xff0c;文章不…

【BFS二叉树】113路径总和II

113路径总和 II 给你二叉树的根节点 root 和一个整数目标和 targetSum &#xff0c;找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。 思路&#xff1a; 题目最终输出的是路径&#xff0c;因此用BFS遍历的时候&#xff0c;需要记录走到每个节点的路径&#xff1…

排序算法之快速排序算法介绍

目录 快速排序介绍 时间复杂度和稳定性 代码实现 C语言实现 c实现 java实现 快速排序介绍 快速排序(Quick Sort)使用分治法策略。 它的基本思想是&#xff1a;选择一个基准数&#xff0c;通过一趟排序将要排序的数据分割成独立的两部分&#xff1b;其中一部分的所有数据…