Deprecate Job/Step builder factories
This commit deprecates JobBuilderFactory and StepBuilderFactory in favor of the respective builders they create. It also removes the exposure of such utilities as beans in the application context when using `@EnableBatchProcessing`. Resolves https://github.com/spring-projects/spring-batch/issues/4188
This commit is contained in:
@@ -18,8 +18,9 @@ package org.springframework.batch.sample.config;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
@@ -39,24 +40,19 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
@EnableBatchProcessing
|
||||
public class RetrySampleConfiguration {
|
||||
|
||||
@Autowired
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
@Autowired
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Bean
|
||||
public Job retrySample() {
|
||||
return jobs.get("retrySample").start(step()).build();
|
||||
public Job retrySample(JobRepository jobRepository) {
|
||||
return new JobBuilder("retrySample").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected Step step() {
|
||||
return steps.get("step").<Trade, Object>chunk(1).transactionManager(this.transactionManager).reader(reader())
|
||||
.writer(writer()).faultTolerant().retry(Exception.class).retryLimit(3).build();
|
||||
protected Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Trade, Object>chunk(1)
|
||||
.transactionManager(this.transactionManager).reader(reader()).writer(writer()).faultTolerant()
|
||||
.retry(Exception.class).retryLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.sample.metrics;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -15,24 +31,19 @@ public class Job1Configuration {
|
||||
|
||||
private Random random;
|
||||
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
public Job1Configuration(JobBuilderFactory jobs, StepBuilderFactory steps) {
|
||||
this.jobs = jobs;
|
||||
this.steps = steps;
|
||||
public Job1Configuration() {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job1() {
|
||||
return jobs.get("job1").start(step1()).next(step2()).build();
|
||||
public Job job1(JobRepository jobRepository) {
|
||||
return new JobBuilder("job1").repository(jobRepository).start(step1(jobRepository)).next(step2(jobRepository))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step1() {
|
||||
return steps.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
public Step step1(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("hello");
|
||||
// simulate processing time
|
||||
Thread.sleep(random.nextInt(3000));
|
||||
@@ -41,8 +52,8 @@ public class Job1Configuration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return steps.get("step2").tasklet((contribution, chunkContext) -> {
|
||||
public Step step2(JobRepository jobRepository) {
|
||||
return new StepBuilder("step2").repository(jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("world");
|
||||
// simulate step failure
|
||||
int nextInt = random.nextInt(3000);
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.sample.metrics;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@@ -6,9 +21,10 @@ import java.util.Random;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.configuration.annotation.StepScope;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
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.support.ListItemReader;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -19,24 +35,19 @@ public class Job2Configuration {
|
||||
|
||||
private Random random;
|
||||
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
public Job2Configuration(JobBuilderFactory jobs, StepBuilderFactory steps) {
|
||||
this.jobs = jobs;
|
||||
this.steps = steps;
|
||||
public Job2Configuration() {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job2() {
|
||||
return jobs.get("job2").start(step()).build();
|
||||
public Job job2(JobRepository jobRepository) {
|
||||
return new JobBuilder("job2").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step() {
|
||||
return steps.get("step1").<Integer, Integer>chunk(3).reader(itemReader()).writer(itemWriter()).build();
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step1").repository(jobRepository).<Integer, Integer>chunk(3).reader(itemReader())
|
||||
.writer(itemWriter()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
* Copyright 2020-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +21,9 @@ import java.util.Map;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.data.MongoItemReader;
|
||||
import org.springframework.batch.item.data.MongoItemWriter;
|
||||
import org.springframework.batch.item.data.builder.MongoItemReaderBuilder;
|
||||
@@ -43,15 +44,6 @@ import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||
@EnableBatchProcessing
|
||||
public class DeletionJobConfiguration {
|
||||
|
||||
private JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
public DeletionJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.stepBuilderFactory = stepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoItemReader<Person> mongoPersonReader(MongoTemplate mongoTemplate) {
|
||||
Map<String, Sort.Direction> sortOptions = new HashMap<>();
|
||||
@@ -68,14 +60,15 @@ public class DeletionJobConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step deletionStep(MongoItemReader<Person> mongoPersonReader, MongoItemWriter<Person> mongoPersonRemover) {
|
||||
return this.stepBuilderFactory.get("step").<Person, Person>chunk(2).reader(mongoPersonReader)
|
||||
public Step deletionStep(JobRepository jobRepository, MongoItemReader<Person> mongoPersonReader,
|
||||
MongoItemWriter<Person> mongoPersonRemover) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Person, Person>chunk(2).reader(mongoPersonReader)
|
||||
.writer(mongoPersonRemover).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job deletionJob(Step deletionStep) {
|
||||
return this.jobBuilderFactory.get("deletionJob").start(deletionStep).build();
|
||||
public Job deletionJob(JobRepository jobRepository, Step deletionStep) {
|
||||
return new JobBuilder("deletionJob").repository(jobRepository).start(deletionStep).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
* Copyright 2020-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +21,9 @@ import java.util.Map;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.data.MongoItemReader;
|
||||
import org.springframework.batch.item.data.MongoItemWriter;
|
||||
import org.springframework.batch.item.data.builder.MongoItemReaderBuilder;
|
||||
@@ -40,15 +41,6 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
@EnableBatchProcessing
|
||||
public class InsertionJobConfiguration {
|
||||
|
||||
private JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
public InsertionJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.stepBuilderFactory = stepBuilderFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoItemReader<Person> mongoItemReader(MongoTemplate mongoTemplate) {
|
||||
Map<String, Sort.Direction> sortOptions = new HashMap<>();
|
||||
@@ -63,14 +55,15 @@ public class InsertionJobConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step(MongoItemReader<Person> mongoItemReader, MongoItemWriter<Person> mongoItemWriter) {
|
||||
return this.stepBuilderFactory.get("step").<Person, Person>chunk(2).reader(mongoItemReader)
|
||||
public Step step(JobRepository jobRepository, MongoItemReader<Person> mongoItemReader,
|
||||
MongoItemWriter<Person> mongoItemWriter) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Person, Person>chunk(2).reader(mongoItemReader)
|
||||
.writer(mongoItemWriter).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job insertionJob(Step step) {
|
||||
return this.jobBuilderFactory.get("insertionJob").start(step).build();
|
||||
public Job insertionJob(JobRepository jobRepository, Step step) {
|
||||
return new JobBuilder("insertionJob").repository(jobRepository).start(step).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.integration.chunk.RemoteChunkingManagerStepBuilderFactory;
|
||||
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
|
||||
@@ -57,9 +58,6 @@ public class ManagerConfiguration {
|
||||
@Value("${broker.url}")
|
||||
private String brokerUrl;
|
||||
|
||||
@Autowired
|
||||
private JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
@Autowired
|
||||
private RemoteChunkingManagerStepBuilderFactory managerStepBuilderFactory;
|
||||
|
||||
@@ -113,8 +111,8 @@ public class ManagerConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job remoteChunkingJob() {
|
||||
return this.jobBuilderFactory.get("remoteChunkingJob").start(managerStep()).build();
|
||||
public Job remoteChunkingJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("remoteChunkingJob").repository(jobRepository).start(managerStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
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.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
|
||||
import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory;
|
||||
import org.springframework.batch.sample.remotepartitioning.BasicPartitioner;
|
||||
@@ -47,14 +48,10 @@ public class ManagerConfiguration {
|
||||
|
||||
private static final int GRID_SIZE = 3;
|
||||
|
||||
private final JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private final RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory;
|
||||
|
||||
public ManagerConfiguration(JobBuilderFactory jobBuilderFactory,
|
||||
RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) {
|
||||
public ManagerConfiguration(RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) {
|
||||
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.managerStepBuilderFactory = managerStepBuilderFactory;
|
||||
}
|
||||
|
||||
@@ -96,8 +93,8 @@ public class ManagerConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job remotePartitioningJob() {
|
||||
return this.jobBuilderFactory.get("remotePartitioningJob").start(managerStep()).build();
|
||||
public Job remotePartitioningJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("remotePartitioningJob").repository(jobRepository).start(managerStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
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.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
|
||||
import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory;
|
||||
import org.springframework.batch.sample.remotepartitioning.BasicPartitioner;
|
||||
@@ -47,14 +48,10 @@ public class ManagerConfiguration {
|
||||
|
||||
private static final int GRID_SIZE = 3;
|
||||
|
||||
private final JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private final RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory;
|
||||
|
||||
public ManagerConfiguration(JobBuilderFactory jobBuilderFactory,
|
||||
RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) {
|
||||
public ManagerConfiguration(RemotePartitioningManagerStepBuilderFactory managerStepBuilderFactory) {
|
||||
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.managerStepBuilderFactory = managerStepBuilderFactory;
|
||||
}
|
||||
|
||||
@@ -82,8 +79,8 @@ public class ManagerConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job remotePartitioningJob() {
|
||||
return this.jobBuilderFactory.get("remotePartitioningJob").start(managerStep()).build();
|
||||
public Job remotePartitioningJob(JobRepository jobRepository) {
|
||||
return new JobBuilder("remotePartitioningJob").repository(jobRepository).start(managerStep()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ import java.util.Arrays;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -40,16 +41,9 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
@Import(DataSourceConfiguration.class)
|
||||
public class SkippableExceptionDuringProcessSample {
|
||||
|
||||
private final JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private final StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
|
||||
public SkippableExceptionDuringProcessSample(JobBuilderFactory jobBuilderFactory,
|
||||
StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager) {
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.stepBuilderFactory = stepBuilderFactory;
|
||||
public SkippableExceptionDuringProcessSample(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
@@ -88,15 +82,15 @@ public class SkippableExceptionDuringProcessSample {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step() {
|
||||
return this.stepBuilderFactory.get("step").<Integer, Integer>chunk(3)
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(3)
|
||||
.transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor())
|
||||
.writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job").start(step()).build();
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ import java.util.Arrays;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -40,16 +41,9 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
@Import(DataSourceConfiguration.class)
|
||||
public class SkippableExceptionDuringReadSample {
|
||||
|
||||
private final JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private final StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
|
||||
public SkippableExceptionDuringReadSample(JobBuilderFactory jobBuilderFactory,
|
||||
StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager) {
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.stepBuilderFactory = stepBuilderFactory;
|
||||
public SkippableExceptionDuringReadSample(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
@@ -88,15 +82,15 @@ public class SkippableExceptionDuringReadSample {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step() {
|
||||
return this.stepBuilderFactory.get("step").<Integer, Integer>chunk(3)
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(3)
|
||||
.transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor())
|
||||
.writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job").start(step()).build();
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ import java.util.Arrays;
|
||||
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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -40,16 +41,9 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
@Import(DataSourceConfiguration.class)
|
||||
public class SkippableExceptionDuringWriteSample {
|
||||
|
||||
private final JobBuilderFactory jobBuilderFactory;
|
||||
|
||||
private final StepBuilderFactory stepBuilderFactory;
|
||||
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
|
||||
public SkippableExceptionDuringWriteSample(JobBuilderFactory jobBuilderFactory,
|
||||
StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager) {
|
||||
this.jobBuilderFactory = jobBuilderFactory;
|
||||
this.stepBuilderFactory = stepBuilderFactory;
|
||||
public SkippableExceptionDuringWriteSample(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
@@ -88,15 +82,15 @@ public class SkippableExceptionDuringWriteSample {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step() {
|
||||
return this.stepBuilderFactory.get("step").<Integer, Integer>chunk(3)
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(3)
|
||||
.transactionManager(this.transactionManager).reader(itemReader()).processor(itemProcessor())
|
||||
.writer(itemWriter()).faultTolerant().skip(IllegalArgumentException.class).skipLimit(3).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job").start(step()).build();
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ 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.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.item.support.ListItemWriter;
|
||||
import org.springframework.batch.item.validator.BeanValidatingItemProcessor;
|
||||
@@ -42,12 +43,6 @@ import org.springframework.jdbc.support.JdbcTransactionManager;
|
||||
@EnableBatchProcessing
|
||||
public class ValidationSampleConfiguration {
|
||||
|
||||
@Autowired
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
@Autowired
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Person> itemReader() {
|
||||
Person person1 = new Person(1, "foo");
|
||||
@@ -70,14 +65,15 @@ public class ValidationSampleConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step() throws Exception {
|
||||
return this.steps.get("step").<Person, Person>chunk(1).transactionManager(transactionManager(dataSource()))
|
||||
.reader(itemReader()).processor(itemValidator()).writer(itemWriter()).build();
|
||||
public Step step(JobRepository jobRepository) throws Exception {
|
||||
return new StepBuilder("step").repository(jobRepository).<Person, Person>chunk(1)
|
||||
.transactionManager(transactionManager(dataSource())).reader(itemReader()).processor(itemValidator())
|
||||
.writer(itemWriter()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() throws Exception {
|
||||
return this.jobs.get("job").start(step()).build();
|
||||
public Job job(JobRepository jobRepository) throws Exception {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -32,9 +32,10 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
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.json.GsonJsonObjectReader;
|
||||
import org.springframework.batch.item.json.JacksonJsonObjectMarshaller;
|
||||
import org.springframework.batch.item.json.JsonItemReader;
|
||||
@@ -73,12 +74,6 @@ class JsonSupportIntegrationTests {
|
||||
@EnableBatchProcessing
|
||||
static class JobConfiguration {
|
||||
|
||||
@Autowired
|
||||
private JobBuilderFactory jobs;
|
||||
|
||||
@Autowired
|
||||
private StepBuilderFactory steps;
|
||||
|
||||
@Bean
|
||||
public JsonItemReader<Trade> itemReader() {
|
||||
return new JsonItemReaderBuilder<Trade>().name("tradesJsonItemReader")
|
||||
@@ -94,14 +89,15 @@ class JsonSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step() {
|
||||
return steps.get("step").<Trade, Trade>chunk(2).transactionManager(transactionManager(dataSource()))
|
||||
.reader(itemReader()).writer(itemWriter()).build();
|
||||
public Step step(JobRepository jobRepository) {
|
||||
return new StepBuilder("step").repository(jobRepository).<Trade, Trade>chunk(2)
|
||||
.transactionManager(transactionManager(dataSource())).reader(itemReader()).writer(itemWriter())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return jobs.get("job").start(step()).build();
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job").repository(jobRepository).start(step(jobRepository)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user