Spring 我希望MultiResourceItemReader处理的当前资源在beforeStep方法中可用
是否有任何方法可以使MultiResourceItemReader处理的currentResource在beforeStep方法中可用。请提供一个工作代码示例。我尝试将multiresourcereader引用注入到stepexecutionlistener,但是spring cglib只接受要注入的接口类型,我不知道是使用ItemReader还是ItemStream接口Spring 我希望MultiResourceItemReader处理的当前资源在beforeStep方法中可用,spring,spring-batch,Spring,Spring Batch,是否有任何方法可以使MultiResourceItemReader处理的currentResource在beforeStep方法中可用。请提供一个工作代码示例。我尝试将multiresourcereader引用注入到stepexecutionlistener,但是spring cglib只接受要注入的接口类型,我不知道是使用ItemReader还是ItemStream接口 目前无法从MultiResourceItemReader检索currentResource。如果需要此API增强,请在中创
- 目前无法从
检索MultiResourceItemReader
。如果需要此API增强,请在中创建一个currentResource
- 即使有
的getter,它的值在currentResource
beforeStep()中也是无效的。它在
和open()
之间有效close()
<bean name="businessStep:master" class="org.springframework.batch.core.partition.support.PartitionStep">
<property name="jobRepository" ref="jobRepository"/>
<property name="stepExecutionSplitter">
<bean class="org.springframework.batch.core.partition.support.SimpleStepExecutionSplitter">
<constructor-arg ref="jobRepository"/>
<constructor-arg ref="concreteBusinessStep"/>
<constructor-arg>
<bean class="org.spring...MultiResourcePartitioner" scope="step">
<property name="resources" value="#{jobParameters['input.file.pattern']}"/>
</bean>
</constructor-arg>
</bean>
</property>
<property name="partitionHandler">
<bean class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler">
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor">
<property name="concurrencyLimit" value="1" />
</bean>
</property>
<property name="step" ref="concreteBusinessStep"/>
</bean>
</property>
</bean>
<bean id="whateverClass" class="..." scope="step">
<property name="resource" value="#{stepExecutionContext['fileName']}" />
</bean>
示例步骤配置:
<job id="renameFilesPartitionJob">
<step id="businessStep"
parent="businessStep:master" />
</job>
<step id="concreteBusinessStep">
<tasklet>
<chunk reader="itemReader"
writer="itemWriter"
commit-interval="5" />
</tasklet>
</step>
潜在缺陷:
- 每个文件的不同步骤,而不是一个步骤
- 更复杂的配置
资源的MultiResourceItemReader方法,更新步骤执行。示例代码如下所示
private StepExecution stepExecution;
@Override
public Resource getCurrentResource() {
this.stepExecution.getJobExecution().getExecutionContext().put("FILE_NAME", super.getCurrentResource().getFilename());
return super.getCurrentResource();
}
@BeforeStep
public void beforeStep(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
如果使正在读取的项实现ResourceAware,则当前资源将设置为读取状态
public class MyItem implements ResourceAware {
private Resource resource;
//others
public void setResource(Resource resource) {
this.resource = resource;
}
public Resource getResource() {
return resource;
}
}
在你的阅读器、处理器或书写器中
myItem.getResource()
将返回从中加载的资源我建议您仔细设置与您的问题相关的标签,以获得更广泛的受众。我不知道你说的主题/应用程序/任何东西是什么,但我确信它不是Windows批处理文件(这是“批处理”标记的目标)。您将MultiResourceItemReader
引用声明为stepexecutionlistener
的想法我并不清楚:对于这个MultiResourceItemReader
应该实现stepexecutionlistener
接口,然后beforeStep()执行步骤之前将调用MultiResourceItemReader
中的:谢谢。我看到了消息来源,没有这方面的规定。