从SCDF启动任务时,如何解决执行“ java.lang.IllegalArgumentException:无效的TaskExecution,ID 3”?

问题描述 投票:0回答:1

我正在尝试通过SCDF运行Spring批处理jar。我在读写时都使用了不同的数据源(两个Oracle DB)。我用来编写的dataSource是主要数据源。我使用自定义构建SCDF来包含oracle驱动程序依赖项。以下是自定义SCDF项目的位置。

dataflow-server-22x

我是我的本地Spring批处理项目,我实现了DefaultTaskConfigurer以提供主要数据源。因此,当我从IDE运行Batch项目时,该项目运行良好,并且它从辅助数据源读取记录并写入主数据源。但是,当我将批处理jar部署为自定义构建SCDF作为任务并启动它时,出现错误,

org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 3 not found

当我检查任务执行表(可以通过主数据源访问)时,该表中有任务执行ID。但是我仍然得到这个错误。对于每次运行,都会将新任务ID插入Task_execution表中,但会收到上述错误消息以及新插入的task_execution ID。以下是项目的详细信息:

Spring-boot-starter-parent : 2.2.5.RELEASE.
Spring-cloud-dataflow : 2.2.0.RELEASE.

我使用批处理作业类的实例从Boot的主类加载我的所有Batch_jobs,只有主类(启动所有作业)包含@EnableTask批注。下面是我的课程结构。

    @SpringBootApplication
    @EnableScheduling
    @EnableTask
    public class SpringBootMainApplication{
        @Autowired
        Job1Loader job1Loader;

        public static void main(String[] args) {
            SpringApplication.run(SpringBootMainApplication.class, args);
        }

        @Scheduled(cron = "0 */1 * * * ?")
        public void executeJob1Loader() throws Exception
        {
            JobParameters param = new JobParametersBuilder()
                                        .addString("JobID",         
                                     String.valueOf(System.currentTimeMillis()))
                                        .toJobParameters();
            jobLauncher.run(job1Loader.loadJob1(), param);
        }
    }

    //Job Config
    @Configuration
    @EnableBatchProcessing
    public class Job1Loader {
    @Bean
        public Job loadJob1()
        {
            return jobBuilderFactory().get("JOb1Loader")
                .incrementer(new RunIdIncrementer())
                .flow(step01())
                .end()
                .build();;//return job
    }

我在Spring作业项目中使用了两个不同的数据源,它们都是oracle数据源(不同的服务器。我将其中一个标记为主要,并在如下所示的“ DefaultTaskConfigurer”的自定义实现中使用了该数据源。

@Configuration
public class TaskConfig extends DefaultTaskConfigurer {
    @Autowired
    DatabaseConfig databaseConfig; 
    @Override
    public DataSource getTaskDataSource() {
        return databaseConfig.dataSource();//dataSource() returns the 
primary ds
    }
}

下面是我在SCDF自定义serer和Spring Batch项目中使用的属性。

UPDATE-1

**Spring batch Job :**
 spring.datasource.jdbc-url=jdbc:oracle:thin:@**MY_PRIMARY_DB**
 spring.datasource.username=db_user
 spring.datasource.password=db_pwd
 spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

spring.datasource.jdbc-url=jdbc:oracle:thin:@**MY_SECONDARY_DB**
 spring.datasource.username=db_user
 spring.datasource.password=db_pwd
 spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

**SCDF custom Server:**
 spring.datasource.url=jdbc:oracle:thin:@**MY_PRIMARY_DB**
 spring.datasource.username=db_user
 spring.datasource.password=db_pwd
 spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

我的批处理应用程序使用两个数据库配置。一读一写。因为源和目的地不同。由于TASK_EXECUTION表是在MY_PRIMARY_DB数据库中创建的,因此我仅传递主db配置供SCDF读取和写入。因为读写发生在同一数据库中。

我对此问题尝试了其他答案,但没有一个有效。正如我之前所说,对此的任何投入都会有很大帮助。谢谢。

java spring oracle spring-batch spring-cloud-dataflow
1个回答
0
投票

而不是像上面所做的那样重写DefaultTaskConfigurer.getTaskDataSource()方法,而是如下更改DefaultTaskConfigurer实现。我还不确定为什么重写方法getTaskDataSource()会导致问题。以下是对我有用的解决方案。

@Configuration
public class TaskConfig extends DefaultTaskConfigurer 
{

    Logger logger = LoggerFactory.getLogger(TaskConfig.class);

    Autowired
    public TaskConfig(@Qualifier("datasource1") DataSource dataSource) {
        super(dataSource); //"datasource1" is reference to the primary datasource.
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.