3

私は 1 つの基本的なステップで 1 つの基本的な仕事をしています。このジョブは x 秒ごとに実行されます (これにはクォーツを使用しています)。次に、構成クラスに変数「runStep」もあります。runStep が true の場合にのみ、この属性をどこに追加してステップを実行する必要がありますか?

<batch:job id="export1" parent="baseJob">
    <batch:step id="registruj" parent="baseStep">
        <tasklet>
            <chunk reader="registrujReader" processor="registrujProcessor" writer="registrujWriter"
                commit-interval="1" />
        </tasklet>
    </batch:step>
</batch:job>

<bean id="baseJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
    <property name="jobRepository" ref="jobRepository" />
</bean>

<bean id="baseStep" class="org.springframework.batch.core.step.factory.SimpleStepFactoryBean" abstract="true">
    <property name="transactionManager" ref="transactionManager" />
    <property name="jobRepository" ref="jobRepository" />
    <property name="startLimit" value="100" />
    <property name="commitInterval" value="1" />
</bean>

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
    p:dataSource-ref="expDataSource" p:transactionManager-ref="transactionManager" />

<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
</bean>

<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
    <property name="jobRegistry" ref="jobRegistry" />
</bean>

<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />

<bean id="registrujWriter" class="cz.isvs.reg.rob.util.export.batch.RegistrujItemWriter" scope="step" />
<bean id="registrujReader" class="cz.isvs.reg.rob.util.export.batch.RegistrujItemReader" scope="step" />
<bean id="registrujProcessor" class="cz.isvs.reg.rob.util.export.batch.RegistrujItemProcessor" scope="step" />

<!-- run every 10 seconds -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail" ref="jobDetail" />
            <property name="cronExpression" value="*/10 * * * * ?" />
        </bean>
    </property>
</bean>

<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="cz.isvs.reg.rob.util.export.batch.JobLauncherDetails" />
    <property name="group" value="quartz-batch" />
    <property name="jobDataAsMap">
        <map>
            <entry key="jobName" value="export1" />
            <entry key="jobLocator" value-ref="jobRegistry" />
            <entry key="jobLauncher" value-ref="jobLauncher" />
        </map>
    </property>
</bean>
4

1 に答える 1

8

使うJobExecutionDecider

public class RunStepDecider implements JobExecutionDecider {
  public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
    final String runStep = jobExecution.getJobParameters().getString("runStep");
    //Depending on the above condition you can return Completed or Failed.
    return new FlowExecutionStatus.COMPLETED;
  }
}
<batch:job id="export1" parent="baseJob">
  <decision id="decision" decider="decider">
    <next on="COMPLETED" to="registruj" />
  </decision>
  <batch:step id="registruj" parent="baseStep">
    <tasklet>
      <chunk reader="registrujReader" processor="registrujProcessor" writer="registrujWriter" commit-interval="1" />
    </tasklet>
  </batch:step>
</batch:job>


<bean id="decider" class="RunStepDecider" />

runStepとして渡しますJobParameter

希望はあなたの問題を解決するのに役立ちます。

于 2013-08-22T09:49:00.957 に答える