【问题标题】:How can I use Spring Cloud Task with modular Spring Batch jobs?如何将 Spring Cloud Task 与模块化 Spring Batch 作业一起使用?
【发布时间】:2020-02-10 15:59:25
【问题描述】:

我在Spring Boot Web 应用程序中开发了几个Spring Batch 工作。为了便于维护,我使用了@EnableBatchProcessing(modular = true),如下所示:

@Configuration
@EnableBatchProcessing(modular = true)
public class BatchConfiguration {

    @Bean
    @ConditionalOnProperty(value="first.batch.enabled", havingValue = "true")
    public ApplicationContextFactory firstJobs() {
        return new GenericApplicationContextFactory(FirstModule.class);
    }

    @Bean
    @ConditionalOnProperty(value="second.batch.enabled", havingValue = "true")
    public ApplicationContextFactory secondJobs() {
        return new GenericApplicationContextFactory(SecondModule.class);
    }
    ...
}

我有@Configuration 类,每个Job 分别在模块的基本目录中定义一个。一切正常,但现在我想设置Spring Cloud Dataflow UI 以对我的Jobs 进行一些基本监控。

问题是,当我尝试将@EnableTask 注释添加到此类BatchConfiguration 时,Spring 没有将作业执行与任务执行相关联。它仅在我运行测试时才有效(@SpringBatchTest)。

我也尝试将@EnableTask 注释添加到FirstJobConfiguration 类,并将其添加到BatchConfigurationFirst|JobConfiguration,但没有任何效果。我也浏览了官方文档,但一无所获。

是否可以将Spring Cloud Task 与模块化Spring Batch 一起使用?

谢谢。

【问题讨论】:

    标签: spring-batch spring-cloud-dataflow spring-cloud-task


    【解决方案1】:

    Spring Batch 应用程序可以转换为 Spring Cloud Task 应用程序并使用 Spring Cloud Data Flow 进行管理。

    您应该能够在 SpringBoot 应用程序中使用 EnableTask 以及在配置中使用 EnableBatchProcessing

    请参阅演示此场景的SCDF sample

    【讨论】:

    • 感谢您的回复,这是完全正确的,但是一旦我将作业定义为模块化,它们就会在其自己的子应用程序上下文中运行每个作业,然后 Spring Cloud Task 无法将 Task 执行与 @987654327 关联@执行
    猜你喜欢
    • 2018-08-31
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多