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.
Is there a way to do that?
@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;
}
This is from BatchAutoConfiguration
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With