春季启动/批量禁用通过代码批量自动启动 [英] spring boot/batch disable batch auto start via code

查看:55
本文介绍了春季启动/批量禁用通过代码批量自动启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Spring Batch应用程序,该应用程序由需要按特定顺序执行的不同作业组成.为此,我通过JobLauncher手动运行作业,并通过在属性文件中添加以下属性来禁用Spring批处理提供的自动启动功能:

I'm writing a spring batch application consisting of different jobs who need to be executed in a specific order. In order to do that I'm running the jobs manually through a JobLauncher, and I disabled the auto start feature provided by Spring batch by adding the following property in my properties file:

spring.batch.job.enabled=false

我想直接在代码中禁用此功能,而不是依靠任何人都可以访问和修改的配置文件.

I would like to disable this feature directly in the code, instead of relying on a configuration file that can be accessed and modified by anyone.

有办法吗?

推荐答案

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled", havingValue = "true", matchIfMissing = true)
public JobLauncherCommandLineRunner jobLauncherCommandLineRunner(
        JobLauncher jobLauncher, JobExplorer jobExplorer) {
    JobLauncherCommandLineRunner runner = new JobLauncherCommandLineRunner(
            jobLauncher, jobExplorer);
    String jobNames = this.properties.getJob().getNames();
    if (StringUtils.hasText(jobNames)) {
        runner.setJobNames(jobNames);
    }
    return runner;
}

这来自 BatchAutoConfiguration .

以此判断,您可以尝试添加自己的 JobLauncherCommandLineRunner 实现,该操作什么也不做.这将影响 @ConditionalOnMissingBean ,并且不应运行.

Judging by this, you could try to add your own implementation of JobLauncherCommandLineRunner which does nothing. This will affect the @ConditionalOnMissingBean and it shouldn't run.

这篇关于春季启动/批量禁用通过代码批量自动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆