robert trudel
robert trudel

Reputation: 5779

how to decide when batch it's starting

I have a spring boot 2 application with spring batch.

Actually when application start, batch is started.

Instead of launching it automatically, I would like to start after a file has been created or modified.

what I need to do to have full control of the batch starting?

@EnableBatchProcessing
@Configuration
public class CsvFileToDatabaseConfig {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Bean
    public FlatFileItemReader<Billings> billingeReader() {
        ....
    }

    @Bean
    ItemProcessor<Billings, Billings> billingProcessor() {
        ...
    }

    @Bean
    public JdbcBatchItemWriter<Billings> billingWriter() {
        ...
    }

    @Bean
    public Step csvFileToDatabaseStep() {
        ...
    }

    @Bean
    Job csvFileToDatabaseJob(JobCompletionNotificationListener listener) {
        ....
    }

}

Upvotes: 0

Views: 130

Answers (1)

Stefan Reisner
Stefan Reisner

Reputation: 705

The answer to your question has two parts: To disable JobLauncherCommandLineRunner that is responsible for launching jobs at startup, set spring.batch.jobs.enabled=false (see also Spring Boot Batch - execluding JobLauncherCommandLineRunner). To launch a job from your application logic, inject the JobLauncher bean and pass its launch method your job bean together with appropriate job parameters.

Upvotes: 2

Related Questions