Updated readers and writers to set platform transaction

It is no longer provided by default by the job builder.

https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#infrastructure-beans-configuration-with-enablebatchbatchprocessing
This commit is contained in:
Glenn Renfro
2022-09-08 19:15:55 -04:00
parent 02f4581f32
commit 87632b3487
19 changed files with 187 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@EnableTask
@SpringBootApplication
@@ -59,6 +60,9 @@ public class BatchEventsApplication {
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
private PlatformTransactionManager transactionManager;
@Bean
public Step step1() {
return this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
@@ -67,7 +71,7 @@ public class BatchEventsApplication {
System.out.println("Tasklet has run");
return RepeatStatus.FINISHED;
}
}).build();
}).transactionManager(transactionManager).build();
}
@Bean
@@ -86,7 +90,7 @@ public class BatchEventsApplication {
System.out.println(">> " + item);
}
}
}).build();
}).transactionManager(transactionManager).build();
}
@Bean

View File

@@ -29,6 +29,7 @@ import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
/**
* @author Michael Minella
@@ -44,6 +45,9 @@ public class JobConfiguration {
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public PlatformTransactionManager transactionManager;
@Bean
public Job job1() {
return this.jobBuilderFactory.get("job1").start(this.stepBuilderFactory.get("job1step1").tasklet(new Tasklet() {
@@ -52,7 +56,7 @@ public class JobConfiguration {
logger.info("Job1 was run");
return RepeatStatus.FINISHED;
}
}).build()).build();
}).transactionManager(transactionManager).build()).build();
}
}