Skip to content
Advertisement

Spring batch job runs automatically

I’m using a spring batch to read a CSV file and write it to the DB, using the controller trigger. On starting the application, before I hit from the browser url, I see the print statements from my reader, on the startup. Although it doesn’t print it for my processor or writer, which are in separate classes which I have autowired. Is it because the reader is a bean?

I see the print statements from my FlatFileItemReader in the log on the application startup. But the print statements for my processor and writer only show up in the console when I hit the controller url. I’ve tried adding spring.batch.job.enabled=false in the application.properties file, but it doesnt stop the execution of the reader bean. How can I prevent auto execution of the reader bean in the SpringBatchConfig class:

SpringBatchConfig class:

JavaScript

DBWriter class:

JavaScript

Processor class:

JavaScript

Controller Class:

JavaScript

Advertisement

Answer

The spring.batch.job.enabled=false property is used to prevent running jobs at application startup.

The method that creates the reader will be still be called at configuration time, so it’s normal that you see the print statement. But that does not mean the reader was called inside a running job.

Advertisement