@Bean
@Qualifier("stepScope")
public org.springframework.batch.core.scope.StepScope stepScope() {
final org.springframework.batch.core.scope.StepScope stepScope = new org.springframework.batch.core.scope.StepScope();
stepScope.setAutoProxy(true);
return stepScope;
}
有了这个改变,我无法在创建bean时传递作业参数,因为它正在抛出
在'org.springframework.beans.factory.config.BeanExpressionContext'类型的对象上找不到'jobParameters'
我的配置就像
@Configuration
@EnableBatchProcessing
public class MyConfig{
@Bean
@Qualifier("partitionJob")
public Job partitionJob() throws Exception {
return jobBuilderFactory
.get("partitionJob")
.incrementer(new RunIdIncrementer())
.start(partitionStep(null))
.build();
}
@Bean
@StepScope
public Step partitionStep(
@Value("#{jobParameters[gridSize]}") String gridSize)
throws Exception {
return stepBuilderFactory
.get("partitionStep")
.partitioner("slaveStep", partitioner())
.gridSize(gridZize)
.step(slaveStep(chunkSize))
.taskExecutor(threadPoolTaskExecutor()).build();
}
@Bean
@StepScope
public Step slaveStep(int chunkSize) throws Exception {
return stepBuilderFactory
.get("slaveStep")
......
........
}
我读过如果需要像我的例子一样访问作业参数,那么应该用@ StepScope注释bean . 但是我正如上面解释的那样得到例外 .