我在不使用ApplicationContext的情况下摆弄Spring Batch。
现在我遇到了障碍,似乎没有办法获得有步骤的实施。它甚至可能吗?
在使用分区步骤时出现问题,不会为每个分区(从属)步骤创建阅读器,可以在https://github.com/hello-spring-batch/hello-spring-batch-usecase-multiresourcepartitioner找到带有测试的源package de.hello.spring.batch;
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.partition.support.MultiResourcePartitioner;
import org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;
public class JobFactory {
public static Job createJob(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository);
StepBuilderFactory stepBuilderFactory = new StepBuilderFactory(jobRepository, transactionManager);
ItemReader reader = new CustomFlatFileItemReader();
ItemWriter writer = new CustomItemWriter();
Step slaveStep = stepBuilderFactory
.get("slaveStep")
.chunk(5)
.reader(reader)
.writer(writer)
.listener(reader)
.build();
MultiResourcePartitioner partitioner = new CustomMultiResourcePartitioner();
SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
taskExecutor.setConcurrencyLimit(4);
TaskExecutorPartitionHandler taskExecutorPartitionHandler = new TaskExecutorPartitionHandler();
taskExecutorPartitionHandler.setTaskExecutor(taskExecutor);
taskExecutorPartitionHandler.setStep(slaveStep);
Step masterStep = stepBuilderFactory
.get("masterStep")
.partitioner("slaveStep", partitioner)
.partitionHandler(taskExecutorPartitionHandler)
.listener(partitioner)
.build();
return jobBuilderFactory
.get("job1")
.start(masterStep)
.build();
}
}