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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user