Spring Batch Disable Meta Data Log

Meta Data Log?

By default, Spring Batch saves status into DataSource.

This is for recover batch. If the batch stops due to errors, the status is saved and developers can check its status and consider recovery way.

But, sometimes this function is annoying. We cannot run same batch with same parameters, or this is small batch, we don’t need to consider intermediate recovery(It’s fine always recover from beginning, just re-run)

What happens without datasource setting?

Let’s run

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Oh, error occurred .

Prevent auto configuration of datasource

To prevent this situation, disable auto setting for datasource. Not save data into datasource.

Create configuration exclude datasource setting


@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class BatchConfiguration {

    private JobBuilderFactory jobBuilderFactory;

    private StepBuilderFactory stepBuilderFactory;

    public Step step1() {
        return stepBuilderFactory.get("step1")
                .tasklet((StepContribution contribution, ChunkContext chunkContext)-> {
                    return RepeatStatus.FINISHED;

    public Job job(Step step1) throws Exception {
        return jobBuilderFactory.get("job1")
                .incrementer(new RunIdIncrementer())

Point is @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})

Professional Programmer2