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:
Mahmoud Ben Hassine
2022-09-13 16:11:28 +02:00
parent 06c2dc3a01
commit 6e443cb1b1
45 changed files with 387 additions and 484 deletions

View File

@@ -49,39 +49,15 @@ import org.springframework.transaction.PlatformTransactionManager;
*/
@Configuration(proxyBeanMethods = false)
@Import(ScopeConfiguration.class)
public abstract class AbstractBatchConfiguration implements InitializingBean {
public abstract class AbstractBatchConfiguration {
private static final Log logger = LogFactory.getLog(AbstractBatchConfiguration.class);
@Autowired
protected ApplicationContext context;
private JobBuilderFactory jobBuilderFactory;
private StepBuilderFactory stepBuilderFactory;
private JobRegistry jobRegistry = new MapJobRegistry();
/**
* Establish the {@link JobBuilderFactory} for the batch execution.
* @return The instance of the {@link JobBuilderFactory}.
* @throws Exception The {@link Exception} thrown if an error occurs.
*/
@Bean
public JobBuilderFactory jobBuilders() throws Exception {
return this.jobBuilderFactory;
}
/**
* Establish the {@link StepBuilderFactory} for the batch execution.
* @return The instance of the {@link StepBuilderFactory}.
* @throws Exception The {@link Exception} thrown if an error occurs.
*/
@Bean
public StepBuilderFactory stepBuilders() throws Exception {
return this.stepBuilderFactory;
}
/**
* Establish the {@link JobRepository} for the batch execution.
* @return The instance of the {@link JobRepository}.
@@ -123,13 +99,6 @@ public abstract class AbstractBatchConfiguration implements InitializingBean {
*/
public abstract PlatformTransactionManager transactionManager() throws Exception;
@Override
public void afterPropertiesSet() throws Exception {
BatchConfigurer batchConfigurer = getOrCreateConfigurer();
this.jobBuilderFactory = new JobBuilderFactory(batchConfigurer.getJobRepository());
this.stepBuilderFactory = new StepBuilderFactory(batchConfigurer.getJobRepository());
}
/**
* If a {@link BatchConfigurer} exists, return it. Otherwise, create a
* {@link DefaultBatchConfigurer}. If more than one configurer is present, an

View File

@@ -44,11 +44,11 @@ import org.springframework.context.annotation.Import;
* public class AppConfig {
*
* @Autowired
* private JobBuilderFactory jobs;
* private JobRepository jobRepository;
*
* @Bean
* public Job job() {
* return jobs.get("myJob").start(step1()).next(step2()).build();
* public Job job(JobRepository jobRepository) {
* return new JobBuilder("myJob").repository(jobRepository).start(step1()).next(step2()).build();
* }
*
* @Bean
@@ -108,12 +108,6 @@ import org.springframework.context.annotation.Import;
* <li>a {@link org.springframework.batch.core.explore.JobExplorer} (bean name
* "jobExplorer" of type
* {@link org.springframework.batch.core.explore.support.SimpleJobExplorer})</li>
* <li>a {@link JobBuilderFactory} (bean name "jobBuilders") as a convenience to prevent
* you from having to inject the job repository into every job, as in the earlier
* examples</li>
* <li>a {@link StepBuilderFactory} (bean name "stepBuilders") as a convenience to prevent
* you from having to inject the job repository and transaction manager into every
* step</li>
* </ul>
*
* The transaction manager provided by this annotation is of type

View File

@@ -25,8 +25,11 @@ import org.springframework.util.Assert;
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @deprecated Deprecated as of v5.0 and scheduled for removal in v5.2 in favor of using
* the {@link JobBuilder}.
*
*/
@Deprecated(since = "5.0.0", forRemoval = true)
public class JobBuilderFactory {
private JobRepository jobRepository;

View File

@@ -26,8 +26,11 @@ import org.springframework.util.Assert;
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @deprecated Deprecated as of v5.0 and scheduled for removal in v5.2 in favor of using
* the {@link StepBuilder}.
*
*/
@Deprecated(since = "5.0.0", forRemoval = true)
public class StepBuilderFactory {
private JobRepository jobRepository;

View File

@@ -24,7 +24,10 @@ import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
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.repeat.RepeatStatus;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -53,21 +56,13 @@ class InlineDataSourceDefinitionTests {
@EnableBatchProcessing
static class MyJobConfiguration {
private JobBuilderFactory jobs;
private StepBuilderFactory steps;
public MyJobConfiguration(JobBuilderFactory jobs, StepBuilderFactory steps) {
this.jobs = jobs;
this.steps = steps;
}
@Bean
public Job job() {
return jobs.get("job").start(steps.get("step").tasklet((contribution, chunkContext) -> {
System.out.println("hello world");
return RepeatStatus.FINISHED;
}).build()).build();
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("hello world");
return RepeatStatus.FINISHED;
}).build()).build();
}
@Bean

View File

@@ -29,10 +29,13 @@ import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
@@ -110,28 +113,28 @@ public class JobBuilderConfigurationTests {
public static class TestConfiguration {
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
private JobRepository jobRepository;
@Autowired
private JdbcTransactionManager transactionManager;
@Bean
public Job testJob() throws Exception {
SimpleJobBuilder builder = jobs.get("test").start(step1()).next(step2());
SimpleJobBuilder builder = new JobBuilder("test").repository(this.jobRepository).start(step1())
.next(step2());
return builder.build();
}
@Bean
protected Step step1() throws Exception {
return steps.get("step1").tasklet(tasklet()).transactionManager(this.transactionManager).build();
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet())
.transactionManager(this.transactionManager).build();
}
@Bean
protected Step step2() throws Exception {
return steps.get("step2").tasklet(tasklet()).transactionManager(this.transactionManager).build();
return new StepBuilder("step2").repository(jobRepository).tasklet(tasklet())
.transactionManager(this.transactionManager).build();
}
@Bean
@@ -155,12 +158,6 @@ public class JobBuilderConfigurationTests {
@Import(DataSourceConfiguration.class)
public static class AnotherConfiguration {
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
@Autowired
private JdbcTransactionManager transactionManager;
@@ -168,14 +165,15 @@ public class JobBuilderConfigurationTests {
private Tasklet tasklet;
@Bean
public Job anotherJob() throws Exception {
SimpleJobBuilder builder = jobs.get("another").start(step3());
public Job anotherJob(JobRepository jobRepository) throws Exception {
SimpleJobBuilder builder = new JobBuilder("another").repository(jobRepository).start(step3(jobRepository));
return builder.build();
}
@Bean
protected Step step3() throws Exception {
return steps.get("step3").tasklet(tasklet).transactionManager(this.transactionManager).build();
protected Step step3(JobRepository jobRepository) throws Exception {
return new StepBuilder("step3").repository(jobRepository).tasklet(tasklet)
.transactionManager(this.transactionManager).build();
}
}
@@ -185,16 +183,13 @@ public class JobBuilderConfigurationTests {
@Import(DataSourceConfiguration.class)
public static class TestConfigurer extends DefaultBatchConfigurer {
@Autowired
private SimpleBatchConfiguration jobs;
public TestConfigurer(DataSource dataSource) {
super(dataSource);
}
@Bean
public Job testConfigurerJob() throws Exception {
SimpleJobBuilder builder = jobs.jobBuilders().get("configurer").start(step1());
public Job testConfigurerJob(JobRepository jobRepository) throws Exception {
SimpleJobBuilder builder = new JobBuilder("configurer").repository(jobRepository).start(step1());
return builder.build();
}
@@ -218,24 +213,18 @@ public class JobBuilderConfigurationTests {
@Import(DataSourceConfiguration.class)
public static class BeansConfigurer {
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
@Autowired
private JdbcTransactionManager transactionManager;
@Bean
public Job beansConfigurerJob() throws Exception {
SimpleJobBuilder builder = jobs.get("beans").start(step1());
public Job beansConfigurerJob(JobRepository jobRepository) throws Exception {
SimpleJobBuilder builder = new JobBuilder("beans").repository(jobRepository).start(step1(jobRepository));
return builder.build();
}
@Bean
protected Step step1() throws Exception {
return steps.get("step1").tasklet(new Tasklet() {
protected Step step1(JobRepository jobRepository) throws Exception {
return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override

View File

@@ -32,9 +32,12 @@ import org.springframework.batch.core.configuration.support.ApplicationContextFa
import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar;
import org.springframework.batch.core.configuration.support.GenericApplicationContextFactory;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
@@ -122,28 +125,23 @@ class JobLoaderConfigurationTests {
};
}
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
@Bean
public Job testJob() throws Exception {
SimpleJobBuilder builder = jobs.get("test").start(step1()).next(step2());
public Job testJob(JobRepository jobRepository) throws Exception {
SimpleJobBuilder builder = new JobBuilder("test").repository(jobRepository).start(step1(jobRepository))
.next(step2(jobRepository));
return builder.build();
}
@Bean
protected Step step1() throws Exception {
return steps.get("step1").tasklet(tasklet()).transactionManager(new ResourcelessTransactionManager())
.build();
protected Step step1(JobRepository jobRepository) throws Exception {
return new StepBuilder("step1").repository(jobRepository).tasklet(tasklet())
.transactionManager(new ResourcelessTransactionManager()).build();
}
@Bean
protected Step step2() throws Exception {
return steps.get("step2").tasklet(tasklet()).transactionManager(new ResourcelessTransactionManager())
.build();
protected Step step2(JobRepository jobRepository) throws Exception {
return new StepBuilder("step2").repository(jobRepository).tasklet(tasklet())
.transactionManager(new ResourcelessTransactionManager()).build();
}
@Bean
@@ -162,21 +160,15 @@ class JobLoaderConfigurationTests {
@Configuration
public static class VanillaConfiguration {
@Autowired
private JobBuilderFactory jobs;
@Autowired
private StepBuilderFactory steps;
@Bean
public Job vanillaJob() throws Exception {
SimpleJobBuilder builder = jobs.get("vanilla").start(step3());
public Job vanillaJob(JobRepository jobRepository) throws Exception {
SimpleJobBuilder builder = new JobBuilder("vanilla").repository(jobRepository).start(step3(jobRepository));
return builder.build();
}
@Bean
protected Step step3() throws Exception {
return steps.get("step3").tasklet(new Tasklet() {
protected Step step3(JobRepository jobRepository) throws Exception {
return new StepBuilder("step3").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext context) throws Exception {

View File

@@ -32,10 +32,9 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.UnexpectedJobExecutionException;
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.configuration.xml.DummyStep;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.FlowStep;
import org.springframework.batch.core.job.flow.support.SimpleFlow;
@@ -47,6 +46,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -74,9 +74,6 @@ class SimpleJobExplorerIntegrationTests {
@EnableBatchProcessing
static class Config {
@Autowired
private StepBuilderFactory steps;
@Bean
public JobExplorer jobExplorer() throws Exception {
return jobExplorerFactoryBean().getObject();
@@ -90,8 +87,8 @@ class SimpleJobExplorerIntegrationTests {
}
@Bean
public Step flowStep() {
return steps.get("flowStep").flow(simpleFlow()).build();
public Step flowStep(JobRepository jobRepository) {
return new StepBuilder("flowStep").repository(jobRepository).flow(simpleFlow()).build();
}
@Bean
@@ -131,8 +128,8 @@ class SimpleJobExplorerIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobBuilderFactory) {
return jobBuilderFactory.get("job").start(dummyStep()).build();
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository).start(dummyStep()).build();
}
}

View File

@@ -34,9 +34,7 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
@@ -44,6 +42,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
@@ -290,19 +289,18 @@ class FlowJobBuilderTests {
@Bean
@JobScope
public Step step(StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager,
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager,
@Value("#{jobParameters['chunkSize']}") Integer chunkSize) {
return stepBuilderFactory.get("step").<Integer, Integer>chunk(chunkSize)
return new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(chunkSize)
.transactionManager(transactionManager).reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4)))
.writer(items -> {
}).build();
}
@Bean
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory,
PlatformTransactionManager transactionManager) {
Step step = step(stepBuilderFactory, transactionManager, null);
return jobBuilderFactory.get("job").flow(step).build().build();
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
Step step = step(jobRepository, transactionManager, null);
return new JobBuilder("job").repository(jobRepository).flow(step).build().build();
}
@Bean

View File

@@ -27,9 +27,9 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.annotation.AfterJob;
import org.springframework.batch.core.annotation.BeforeJob;
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.launch.JobLauncher;
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.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -70,11 +70,11 @@ class JobBuilderTests {
static class MyJobConfiguration {
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job").listener(new InterfaceBasedJobExecutionListener())
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository).listener(new InterfaceBasedJobExecutionListener())
.listener(new AnnotationBasedJobExecutionListener())
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -33,10 +33,11 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
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.launch.support.RunIdIncrementer;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
@@ -131,18 +132,20 @@ class ItemListenerErrorTests {
public static class BatchConfiguration {
@Bean
public Job testJob(JobBuilderFactory jobs, Step testStep) {
return jobs.get("testJob").incrementer(new RunIdIncrementer()).start(testStep).build();
public Job testJob(JobRepository jobRepository, Step testStep) {
return new JobBuilder("testJob").repository(jobRepository).incrementer(new RunIdIncrementer())
.start(testStep).build();
}
@Bean
public Step step1(StepBuilderFactory stepBuilderFactory, PlatformTransactionManager transactionManager,
public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager,
ItemReader<String> fakeItemReader, ItemProcessor<String, String> fakeProcessor,
ItemWriter<String> fakeItemWriter, ItemProcessListener<String, String> itemProcessListener) {
return stepBuilderFactory.get("testStep").<String, String>chunk(10).transactionManager(transactionManager)
.reader(fakeItemReader).processor(fakeProcessor).writer(fakeItemWriter)
.listener(itemProcessListener).faultTolerant().skipLimit(50).skip(RuntimeException.class).build();
return new StepBuilder("testStep").repository(jobRepository).<String, String>chunk(10)
.transactionManager(transactionManager).reader(fakeItemReader).processor(fakeProcessor)
.writer(fakeItemWriter).listener(itemProcessListener).faultTolerant().skipLimit(50)
.skip(RuntimeException.class).build();
}
@Bean

View File

@@ -35,9 +35,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.support.ListItemReader;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.ApplicationContext;
@@ -222,36 +223,30 @@ class BatchMetricsTests {
@Import(DataSoourceConfiguration.class)
static class MyJobConfiguration {
private JobBuilderFactory jobBuilderFactory;
private StepBuilderFactory stepBuilderFactory;
private PlatformTransactionManager transactionManager;
public MyJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory,
PlatformTransactionManager transactionManager) {
this.jobBuilderFactory = jobBuilderFactory;
this.stepBuilderFactory = stepBuilderFactory;
public MyJobConfiguration(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Bean
public Step step1() {
return stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Step step1(JobRepository jobRepository) {
return new StepBuilder("step1").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(this.transactionManager).build();
}
@Bean
public Step step2() {
return stepBuilderFactory.get("step2").<Integer, Integer>chunk(2)
public Step step2(JobRepository jobRepository) {
return new StepBuilder("step2").repository(jobRepository).<Integer, Integer>chunk(2)
.transactionManager(this.transactionManager)
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4, 5)))
.writer(items -> items.forEach(System.out::println)).build();
}
@Bean
public Step step3() {
return stepBuilderFactory.get("step3").<Integer, Integer>chunk(2)
public Step step3(JobRepository jobRepository) {
return new StepBuilder("step3").repository(jobRepository).<Integer, Integer>chunk(2)
.transactionManager(this.transactionManager)
.reader(new ListItemReader<>(Arrays.asList(6, 7, 8, 9, 10)))
.writer(items -> items.forEach(System.out::println)).faultTolerant().skip(Exception.class)
@@ -259,8 +254,9 @@ class BatchMetricsTests {
}
@Bean
public Job job() {
return jobBuilderFactory.get("job").start(step1()).next(step2()).next(step3()).build();
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository).start(step1(jobRepository))
.next(step2(jobRepository)).next(step3(jobRepository)).build();
}
}

View File

@@ -34,9 +34,9 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
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.scope.context.ChunkContext;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemReader;
@@ -128,15 +128,9 @@ class RegisterMultiListenerTests {
public static abstract class MultiListenerTestConfigurationSupport {
@Autowired
protected JobBuilderFactory jobBuilders;
@Autowired
protected StepBuilderFactory stepBuilders;
@Bean
public Job testJob() {
return jobBuilders.get("testJob").start(step()).build();
public Job testJob(JobRepository jobRepository) {
return new JobBuilder("testJob").repository(jobRepository).start(step(jobRepository)).build();
}
@Bean
@@ -186,7 +180,7 @@ class RegisterMultiListenerTests {
};
}
public abstract Step step();
public abstract Step step(JobRepository jobRepository);
}
@@ -209,8 +203,8 @@ class RegisterMultiListenerTests {
@Override
@Bean
public Step step() {
return stepBuilders.get("step").listener(listener()).<String, String>chunk(2)
public Step step(JobRepository jobRepository) {
return new StepBuilder("step").repository(jobRepository).listener(listener()).<String, String>chunk(2)
.transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer())
.faultTolerant().skipLimit(1).skip(MySkippableException.class)
// ChunkListener registered twice for checking BATCH-2149
@@ -238,8 +232,8 @@ class RegisterMultiListenerTests {
@Override
@Bean
public Step step() {
return stepBuilders.get("step").listener(listener()).<String, String>chunk(2)
public Step step(JobRepository jobRepository) {
return new StepBuilder("step").repository(jobRepository).listener(listener()).<String, String>chunk(2)
.transactionManager(transactionManager(dataSource())).reader(reader()).writer(writer()).build();
}

View File

@@ -31,14 +31,14 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;
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.FlowBuilder;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
@@ -90,12 +90,6 @@ class ConcurrentTransactionTests {
@Import(DataSourceConfiguration.class)
public static class ConcurrentJobConfiguration extends DefaultBatchConfigurer {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
public ConcurrentJobConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) {
super(dataSource, transactionManager);
}
@@ -106,15 +100,17 @@ class ConcurrentTransactionTests {
}
@Bean
public Flow flow() {
return new FlowBuilder<Flow>("flow").start(stepBuilderFactory.get("flow.step1").tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
}).transactionManager(getTransactionManager()).build())
.next(stepBuilderFactory.get("flow.step2").tasklet(new Tasklet() {
public Flow flow(JobRepository jobRepository) {
return new FlowBuilder<Flow>("flow")
.start(new StepBuilder("flow.step1").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
return RepeatStatus.FINISHED;
}
}).transactionManager(getTransactionManager()).build())
.next(new StepBuilder("flow.step2").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
@@ -125,8 +121,8 @@ class ConcurrentTransactionTests {
}
@Bean
public Step firstStep() {
return stepBuilderFactory.get("firstStep").tasklet(new Tasklet() {
public Step firstStep(JobRepository jobRepository) {
return new StepBuilder("firstStep").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
@@ -137,8 +133,8 @@ class ConcurrentTransactionTests {
}
@Bean
public Step lastStep() {
return stepBuilderFactory.get("lastStep").tasklet(new Tasklet() {
public Step lastStep(JobRepository jobRepository) {
return new StepBuilder("lastStep").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
@@ -149,12 +145,15 @@ class ConcurrentTransactionTests {
}
@Bean
public Job concurrentJob() {
public Job concurrentJob(JobRepository jobRepository) {
Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(new SimpleAsyncTaskExecutor())
.add(flow(), flow(), flow(), flow(), flow(), flow(), flow()).build();
.add(flow(jobRepository), flow(jobRepository), flow(jobRepository), flow(jobRepository),
flow(jobRepository), flow(jobRepository), flow(jobRepository))
.build();
return jobBuilderFactory.get("concurrentJob").start(firstStep())
.next(stepBuilderFactory.get("splitFlowStep").flow(splitFlow).build()).next(lastStep()).build();
return new JobBuilder("concurrentJob").repository(jobRepository).start(firstStep(jobRepository))
.next(new StepBuilder("splitFlowStep").repository(jobRepository).flow(splitFlow).build())
.next(lastStep(jobRepository)).build();
}
@Override

View File

@@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -112,10 +113,10 @@ class Db2JobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -25,9 +25,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -82,10 +83,10 @@ class DerbyJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -27,9 +27,10 @@ import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
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.repeat.RepeatStatus;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -91,9 +92,10 @@ class H2CompatibilityModeJobRepositoryIntegrationTests {
}
@Bean
Job job(JobBuilderFactory jobs, StepBuilderFactory steps, PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -25,9 +25,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -82,10 +83,10 @@ class H2JobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -33,9 +33,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -120,9 +121,9 @@ class HANAJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step")
.repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
.build();
}

View File

@@ -25,9 +25,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -82,10 +83,10 @@ class HSQLDBJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -34,14 +34,14 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.configuration.JobRegistry;
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.configuration.support.JobRegistryBeanPostProcessor;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.launch.support.SimpleJobOperator;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -138,11 +138,11 @@ class MySQLJdbcJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job").start(steps.get("step").tasklet((contribution, chunkContext) -> {
throw new Exception("expected failure");
}).transactionManager(transactionManager).build()).build();
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository).tasklet((contribution, chunkContext) -> {
throw new Exception("expected failure");
}).transactionManager(transactionManager).build()).build();
}
@Bean

View File

@@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -109,10 +110,10 @@ class MySQLJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -32,9 +32,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -110,9 +111,9 @@ class OracleJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step")
.repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
.build();
}

View File

@@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -108,10 +109,10 @@ class PostgreSQLJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -31,9 +31,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -109,10 +110,10 @@ class SQLServerJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -26,9 +26,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -89,10 +90,10 @@ class SQLiteJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps,
PlatformTransactionManager transactionManager) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager).build())
.build();
}

View File

@@ -28,9 +28,10 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -104,9 +105,9 @@ class SybaseJobRepositoryIntegrationTests {
}
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
return jobs.get("job")
.start(steps.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository).start(new StepBuilder("step")
.repository(jobRepository).tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED).build())
.build();
}

View File

@@ -29,9 +29,9 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.FaultTolerantStepBuilder;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy;
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
import org.springframework.batch.core.step.skip.SkipPolicy;
@@ -77,7 +77,7 @@ class FaultTolerantStepIntegrationTests {
}
};
skipPolicy = new SkipIllegalArgumentExceptionSkipPolicy();
stepBuilder = new StepBuilderFactory(jobRepository).get("step").<Integer, Integer>chunk(CHUNK_SIZE)
stepBuilder = new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(CHUNK_SIZE)
.transactionManager(transactionManager).reader(itemReader).processor(item -> item > 20 ? null : item)
.writer(itemWriter).faultTolerant();
}
@@ -178,7 +178,7 @@ class FaultTolerantStepIntegrationTests {
}
};
Step step = new StepBuilderFactory(jobRepository).get("step").<Integer, Integer>chunk(5)
Step step = new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(5)
.transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter)
.faultTolerant().skip(Exception.class).skipLimit(3).build();
@@ -218,7 +218,7 @@ class FaultTolerantStepIntegrationTests {
}
};
Step step = new StepBuilderFactory(jobRepository).get("step").<Integer, Integer>chunk(5)
Step step = new StepBuilder("step").repository(jobRepository).<Integer, Integer>chunk(5)
.transactionManager(transactionManager).reader(itemReader).processor(itemProcessor).writer(itemWriter)
.faultTolerant().skipPolicy(new AlwaysSkipItemSkipPolicy()).build();

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -24,9 +24,10 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
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.scope.context.ChunkContext;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
@@ -79,15 +80,9 @@ class JobLauncherTestUtilsTests {
@EnableBatchProcessing
static class TestJobConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Bean
public Step step() {
return stepBuilderFactory.get("step1").tasklet(new Tasklet() {
public Step step(JobRepository jobRepository) {
return new StepBuilder("step1").repository(jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
@@ -97,14 +92,14 @@ class JobLauncherTestUtilsTests {
}
@Bean
public Job job() {
return jobBuilderFactory.get("job").flow(step()).end().build();
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository).flow(step(jobRepository)).end().build();
}
@Bean
public JobLauncherTestUtils testUtils() {
public JobLauncherTestUtils testUtils(Job jobUnderTest) {
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(job());
jobLauncherTestUtils.setJob(jobUnderTest);
return jobLauncherTestUtils;
}

View File

@@ -28,10 +28,11 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.JobScope;
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.ItemReader;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.RepeatStatus;
@@ -118,12 +119,6 @@ public class SpringBatchTestJUnit4Tests {
@EnableBatchProcessing
public static class JobConfiguration {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
@@ -149,9 +144,9 @@ public class SpringBatchTestJUnit4Tests {
}
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(this.stepBuilderFactory.get("step")
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager(dataSource())).build())
.build();

View File

@@ -29,10 +29,11 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.JobScope;
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.ItemReader;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.RepeatStatus;
@@ -143,9 +144,10 @@ public class SpringBatchTestJUnit5Tests {
}
@Bean
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
return jobBuilderFactory.get("job")
.start(stepBuilderFactory.get("step").tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
public Job job(JobRepository jobRepository) {
return new JobBuilder("job").repository(jobRepository)
.start(new StepBuilder("step").repository(jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.transactionManager(transactionManager(dataSource())).build())
.build();
}

View File

@@ -31,9 +31,10 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.annotation.AfterStep;
import org.springframework.batch.core.annotation.BeforeStep;
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.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.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
@@ -99,12 +100,6 @@ class StepScopeAnnotatedListenerIntegrationTests {
@EnableBatchProcessing
static class TestConfig {
@Autowired
private JobBuilderFactory jobBuilder;
@Autowired
private StepBuilderFactory stepBuilder;
@Autowired
private PlatformTransactionManager transactionManager;
@@ -127,13 +122,14 @@ class StepScopeAnnotatedListenerIntegrationTests {
}
@Bean
public Job jobUnderTest() {
return jobBuilder.get("job-under-test").start(stepUnderTest()).build();
public Job jobUnderTest(JobRepository jobRepository) {
return new JobBuilder("job-under-test").repository(jobRepository).start(stepUnderTest(jobRepository))
.build();
}
@Bean
public Step stepUnderTest() {
return stepBuilder.get("step-under-test").<String, String>chunk(1)
public Step stepUnderTest(JobRepository jobRepository) {
return new StepBuilder("step-under-test").repository(jobRepository).<String, String>chunk(1)
.transactionManager(this.transactionManager).reader(reader()).processor(processor())
.writer(writer()).build();
}