how to stop spring batch scheduled jobs from running at first time when executing the code? how to stop spring batch scheduled jobs from running at first time when executing the code? spring spring

how to stop spring batch scheduled jobs from running at first time when executing the code?


I had the same problem and determined that it was caused by Spring boot's autoconfiguration service. By default, it will run all configured job beans after application start.

There are two properties that affect this behavior:

  • spring.batch.job.enabled
  • spring.batch.job.names

The first prevents the launching of all jobs when set to false. The second accepts a comma-delimited list of job names that will be run.

These two properties can be set a variety of ways specified in the Spring boot docs:

  1. Command line (--spring.batch.job.enabled=false)
  2. Java system properties (-Dspring.batch.job.enabled=false)
  3. OS environment variables
  4. @PropertySource annotations
  5. application.properties file in the jar directory
  6. application.properties file inside the jar
  7. SpringApplication.setDefaultProperties


adding

spring.batch.job.enabled=false

in application.properties works with me.


To solve this you will have to create one more properties file and name it "batch.properties".

# Disable batch auto-startspring.batch.job.enabled=false

You can give the reference to this file from your java configuration file.

Sample:

@Configuration@ComponentScan("com.code")@EnableBatchProcessing@PropertySource("classpath:batch.properties")public class AppConfig {}

@PropertySource("classpath:batch.properties")

Hope this helps.