Closed s-fj closed 7 months ago
Please fill it out carefully, or it will be closed. 请认真填写,不然会直接关闭。
JDK Version(required): 1.8
SpringBoot Version(required): 2.6.8
dynamic-datasource-spring-boot-starter Version(required):4.1.3
druid Version(optional):1.2.4
/**
Expected Result: 查询 单独查询方法"jtfftbankinnerDao.queryByPage"与单独批量插入"taSingleBillDao.saveBatch"都没有问题 但是写一起就切换不了数据源,jtfftbankinnerDao 对应Oracle,taSingleBillDao对应MySQL-- oracle 读正常 日志如下: 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] AbstractStep Executing: id=2 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.update]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Initiating transaction commit 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction@646d695c] 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2024-02-27 00:16:28.691 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Initiating transaction commit 2024-02-27 00:16:28.691 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction@1d2a605e] 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] RepeatTemplate Starting repeat context. 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] RepeatTemplate Repeat operation about to start at count=1 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] StepContextRepeatCallback Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@74d22751 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] StepContextRepeatCallback Chunk execution starting: queue size=0 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] guration$ReferenceTargetSource Initializing lazy target object 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] StepScope Creating object in scope=step, name=scopedTarget.taSingleBillTasklet 2024-02-27 00:16:28.816 DEBUG 7012 [chTask-1] SqlSessionUtils Creating a new SqlSession 2024-02-27 00:16:28.816 DEBUG 7012 [chTask-1] SqlSessionUtils Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a557aa0] 2024-02-27 00:16:28.878 DEBUG 7012 [chTask-1] DataSourceUtils Fetching JDBC Connection from DataSource 2024-02-27 00:16:28.878 DEBUG 7012 [chTask-1] DynamicRoutingDataSource dynamic-datasource switch to the datasource named [oracleDB] 2024-02-27 00:16:28.878 DEBUG 7012 [chTask-1] SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@70605c7] will be managed by Spring 2024-02-27 00:16:28.894 DEBUG 7012 [chTask-1] queryByPage ==> Preparing: SELECT FROM ( SELECT t., ROWNUM rn FROM ( ... 2024-02-27 00:16:28.987 DEBUG 7012 [chTask-1] queryByPage ==> Parameters: 800515721(String), 1000(Integer), 0(Integer), 0(Integer) 2024-02-27 00:16:29.081 DEBUG 7012 [chTask-1] queryByPage <== Total: 25 2024-02-27 00:16:29.081 DEBUG 7012 [chTask-1] PreparedStatementPool {conn-10005, pstmt-20001} enter cache 2024-02-27 00:16:29.081 DEBUG 7012 [chTask-1] SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a557aa0] 2024-02-27 00:16:29.081 INFO 7012 [chTask-1] TaSingleBillTasklet 批量保存数据: 25 条 2024-02-27 00:16:29.097 DEBUG 7012 [chTask-1] guration$ReferenceTargetSource Initializing lazy target object 2024-02-27 00:16:29.097 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Participating in existing transaction 2024-02-27 00:16:29.159 DEBUG 7012 [chTask-1] SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@70605c7] will be managed by Spring 2024-02-27 00:16:29.159 DEBUG 7012 [chTask-1] insert ==> Preparing: INSERT INTO ta_single_bill ...
后面是insert到Oracle数据库了,没有切换数据源。两个调用的Dao也按照mpdemo模板重写了mybatisplus的方法并加了DS注解,如果读不使用mybatis,手写JDBC,后面写也正常。
Actual Result:
If there is an exception,or aop invalid,please attach the exception trace:
Just paste your stack trace here!
Step 1
Step 2
Step 3
检查事务,自己断点
Please fill it out carefully, or it will be closed. 请认真填写,不然会直接关闭。
Enviroment
JDK Version(required): 1.8
SpringBoot Version(required): 2.6.8
dynamic-datasource-spring-boot-starter Version(required):4.1.3
druid Version(optional):1.2.4
Describe what happened
/**
Expected Result: 查询 单独查询方法"jtfftbankinnerDao.queryByPage"与单独批量插入"taSingleBillDao.saveBatch"都没有问题 但是写一起就切换不了数据源,jtfftbankinnerDao 对应Oracle,taSingleBillDao对应MySQL-- oracle 读正常 日志如下: 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] AbstractStep Executing: id=2 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.update]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Initiating transaction commit 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction@646d695c] 2024-02-27 00:16:28.675 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2024-02-27 00:16:28.691 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Initiating transaction commit 2024-02-27 00:16:28.691 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction@1d2a605e] 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] RepeatTemplate Starting repeat context. 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] RepeatTemplate Repeat operation about to start at count=1 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] StepContextRepeatCallback Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@74d22751 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] StepContextRepeatCallback Chunk execution starting: queue size=0 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] guration$ReferenceTargetSource Initializing lazy target object 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT 2024-02-27 00:16:28.707 DEBUG 7012 [chTask-1] StepScope Creating object in scope=step, name=scopedTarget.taSingleBillTasklet 2024-02-27 00:16:28.816 DEBUG 7012 [chTask-1] SqlSessionUtils Creating a new SqlSession 2024-02-27 00:16:28.816 DEBUG 7012 [chTask-1] SqlSessionUtils Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a557aa0] 2024-02-27 00:16:28.878 DEBUG 7012 [chTask-1] DataSourceUtils Fetching JDBC Connection from DataSource 2024-02-27 00:16:28.878 DEBUG 7012 [chTask-1] DynamicRoutingDataSource dynamic-datasource switch to the datasource named [oracleDB] 2024-02-27 00:16:28.878 DEBUG 7012 [chTask-1] SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@70605c7] will be managed by Spring 2024-02-27 00:16:28.894 DEBUG 7012 [chTask-1] queryByPage ==> Preparing: SELECT FROM ( SELECT t., ROWNUM rn FROM ( ... 2024-02-27 00:16:28.987 DEBUG 7012 [chTask-1] queryByPage ==> Parameters: 800515721(String), 1000(Integer), 0(Integer), 0(Integer) 2024-02-27 00:16:29.081 DEBUG 7012 [chTask-1] queryByPage <== Total: 25 2024-02-27 00:16:29.081 DEBUG 7012 [chTask-1] PreparedStatementPool {conn-10005, pstmt-20001} enter cache 2024-02-27 00:16:29.081 DEBUG 7012 [chTask-1] SqlSessionUtils Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a557aa0] 2024-02-27 00:16:29.081 INFO 7012 [chTask-1] TaSingleBillTasklet 批量保存数据: 25 条 2024-02-27 00:16:29.097 DEBUG 7012 [chTask-1] guration$ReferenceTargetSource Initializing lazy target object 2024-02-27 00:16:29.097 DEBUG 7012 [chTask-1] ResourcelessTransactionManager Participating in existing transaction 2024-02-27 00:16:29.159 DEBUG 7012 [chTask-1] SpringManagedTransaction JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@70605c7] will be managed by Spring 2024-02-27 00:16:29.159 DEBUG 7012 [chTask-1] insert ==> Preparing: INSERT INTO ta_single_bill ...
后面是insert到Oracle数据库了,没有切换数据源。两个调用的Dao也按照mpdemo模板重写了mybatisplus的方法并加了DS注解,如果读不使用mybatis,手写JDBC,后面写也正常。
Actual Result:
If there is an exception,or aop invalid,please attach the exception trace:
Steps to reproduce
Step 1
Step 2
Step 3