Skip to content

调度spring batch job无法支持多数据源 默认使用主数据源 #773

Description

@Liujin0411

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执行期间

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions