Describe the bug
在Spring Batch Job环境中,@DS("")注解未能正确切换数据源,导致数据库操作仍然在默认的主数据源执行,而不是在预期的从数据源上执行。这导致了Table doesn't exist错误。
To Reproduce
Reference code:
@bean
public Tasklet syncCleanTasklet() {
return (contribution, chunkContext) -> {
testMapper.removeAll();
return RepeatStatus.FINISHED;
};
}
@bean
public Step syncCleanStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
return new StepBuilder("syncCleanStep", jobRepository)
.tasklet(syncCleanTasklet(), transactionManager)
.build();
}
@bean
public Job syncJob(JobRepository jobRepository,
Step syncCleanStep,
Step syncStep) {
return new JobBuilder("syncJob", jobRepository)
.start(syncCleanStep)
.next(syncStep)
.build();
}
@Mapper
@ds("starrocks")
public interface TestMapper{
void removeAll();
}
执行报错:### Cause: java.sql.SQLSyntaxErrorException: Table 'db.test' doesn't exist
Additional context
- 使用的技术栈:Spring Boot, Spring Batch, dynamic-datasource-spring-boot-starter
- 问题出现的环境:Spring Batch Job执行期间
Describe the bug
在Spring Batch Job环境中,
@DS("")注解未能正确切换数据源,导致数据库操作仍然在默认的主数据源执行,而不是在预期的从数据源上执行。这导致了Table doesn't exist错误。To Reproduce
Reference code:
@bean
public Tasklet syncCleanTasklet() {
return (contribution, chunkContext) -> {
testMapper.removeAll();
return RepeatStatus.FINISHED;
};
}
@bean
public Step syncCleanStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager) {
return new StepBuilder("syncCleanStep", jobRepository)
.tasklet(syncCleanTasklet(), transactionManager)
.build();
}
@bean
public Job syncJob(JobRepository jobRepository,
Step syncCleanStep,
Step syncStep) {
return new JobBuilder("syncJob", jobRepository)
.start(syncCleanStep)
.next(syncStep)
.build();
}
@Mapper
@ds("starrocks")
public interface TestMapper{
void removeAll();
}
执行报错:### Cause: java.sql.SQLSyntaxErrorException: Table 'db.test' doesn't exist
Additional context