I am using spring boot 3.4 below is my BatchConfig. It’s running at startup of the application even I have added required property to disabled at start:
@Configuration
@EnableBatchProcessing
@RequiredArgsConstructor
public class BatchConfig {
private static final int BATCH_SIZE = 1000;
private final EmployeeReadService readService;
private final EmployeeWriteService writeService;
private final EmployeeProcessService processService;
private final JobRepository jobRepository;
private final PlatformTransactionManager transactionManager;
// Job Configuration
@Bean
public Job migrationJob(Step migrateStep) {
return new JobBuilder("migrationJob", jobRepository)
.start(migrateStep)
.preventRestart()
.build();
}
// Step Configuration
@Bean
public Step migrateStep() throws Exception {
return new StepBuilder("migrateStep", jobRepository)
.<SourceEmployee, DestinationEmployee>chunk(BATCH_SIZE, transactionManager)
.reader(readService.reader()) // Paginated reader
.processor(processService.processor())
.writer(writeService.writer())
.build();
}
}
application.yml:
spring:
batch:
job:
enabled: false
h2:
console:
enabled: true
path: /h2-console
sql:
init:
mode: always
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
driver-class-name: org.h2.Driver
username: sa
password:
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
1