diff --git a/pom.xml b/pom.xml
index d44b836607..ca55866a42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -759,6 +759,7 @@
javafx
spring-batch
+ spring-batch-2
spring-boot-rest
spring-drools
spring-exceptions
@@ -781,7 +782,6 @@
server-modules
apache-cxf-modules
-
spring-aop
jmeter
spring-aop-2
@@ -928,7 +928,6 @@
spring-5-webflux
spring-5-webflux-2
spring-activiti
- spring-batch-2
spring-core-2
spring-core-3
spring-core-5
@@ -1012,6 +1011,7 @@
javafx
spring-batch
+ spring-batch-2
spring-boot-rest
spring-drools
spring-exceptions
@@ -1180,7 +1180,6 @@
spring-5-webflux
spring-5-webflux-2
spring-activiti
- spring-batch-2
spring-core-2
spring-core-3
spring-core-5
diff --git a/spring-batch-2/pom.xml b/spring-batch-2/pom.xml
index 12d31aca14..378191c91c 100644
--- a/spring-batch-2/pom.xml
+++ b/spring-batch-2/pom.xml
@@ -11,9 +11,9 @@
com.baeldung
- parent-boot-2
+ parent-boot-3
0.0.1-SNAPSHOT
- ../parent-boot-2
+ ../parent-boot-3
@@ -51,8 +51,9 @@
- 4.3.0
- 3.1.1
+ 5.0.0
+ 4.2.0
+ com.baeldung.batch.SpringBootBatchProcessingApplication
\ No newline at end of file
diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java b/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java
index 0c053dd86c..770b6330dd 100644
--- a/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java
+++ b/spring-batch-2/src/main/java/com/baeldung/batch/BatchConfiguration.java
@@ -4,31 +4,24 @@ import javax.sql.DataSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
-import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
-import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
-import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
+import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
+import org.springframework.batch.core.repository.JobRepository;
+import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.transaction.PlatformTransactionManager;
@Configuration
-@EnableBatchProcessing
public class BatchConfiguration {
-
- @Autowired
- public JobBuilderFactory jobBuilderFactory;
-
- @Autowired
- public StepBuilderFactory stepBuilderFactory;
@Value("${file.input}")
private String fileInput;
@@ -59,8 +52,8 @@ public class BatchConfiguration {
}
@Bean
- public Job importUserJob(JobCompletionNotificationListener listener, Step step1) {
- return jobBuilderFactory.get("importUserJob")
+ public Job importUserJob(JobRepository jobRepository, JobCompletionNotificationListener listener, Step step1) {
+ return new JobBuilder("importUserJob", jobRepository)
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(step1)
@@ -69,9 +62,9 @@ public class BatchConfiguration {
}
@Bean
- public Step step1(JdbcBatchItemWriter writer) {
- return stepBuilderFactory.get("step1")
- . chunk(10)
+ public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager, JdbcBatchItemWriter writer) {
+ return new StepBuilder("step1", jobRepository)
+ . chunk(10, transactionManager)
.reader(reader())
.processor(processor())
.writer(writer)
diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java b/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java
index b154b80453..bd4173e9ed 100644
--- a/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java
+++ b/spring-batch-2/src/main/java/com/baeldung/batch/CoffeeItemProcessor.java
@@ -10,7 +10,7 @@ public class CoffeeItemProcessor implements ItemProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(CoffeeItemProcessor.class);
@Override
- public Coffee process(final Coffee coffee) throws Exception {
+ public Coffee process(final Coffee coffee) {
String brand = coffee.getBrand().toUpperCase();
String origin = coffee.getOrigin().toUpperCase();
String chracteristics = coffee.getCharacteristics().toUpperCase();
diff --git a/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java b/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java
index ca1de40aea..b61faeb13b 100644
--- a/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java
+++ b/spring-batch-2/src/main/java/com/baeldung/batch/JobCompletionNotificationListener.java
@@ -4,13 +4,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
-import org.springframework.batch.core.listener.JobExecutionListenerSupport;
+import org.springframework.batch.core.JobExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
@Component
-public class JobCompletionNotificationListener extends JobExecutionListenerSupport {
+public class JobCompletionNotificationListener implements JobExecutionListener {
private static final Logger LOGGER = LoggerFactory.getLogger(JobCompletionNotificationListener.class);
diff --git a/spring-batch-2/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java b/spring-batch-2/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java
index c830a41855..dcb2bc5199 100644
--- a/spring-batch-2/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java
+++ b/spring-batch-2/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java
@@ -7,15 +7,16 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
-import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
-import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
-import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
+import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
+import org.springframework.batch.core.repository.JobRepository;
+import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
@@ -24,17 +25,16 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.ScheduledMethodRunnable;
+import org.springframework.transaction.PlatformTransactionManager;
import java.util.Date;
import java.util.IdentityHashMap;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@Configuration
-@EnableBatchProcessing
@EnableScheduling
public class SpringBatchScheduler {
@@ -46,21 +46,21 @@ public class SpringBatchScheduler {
private final Map