们可以在没有ItemReader和ItemWriter的情况下编

们可以在没有ItemReader和ItemWriter的情况下编

本文介绍了我们可以在没有ItemReader和ItemWriter的情况下编写Spring Batch作业吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我用Spring Batch 2.2编写了一个Quartz调度程序.

根据我的要求,我想运行一个调度程序以获取应用程序的config属性,以刷新所有GlassFish群集上的配置缓存.

因此,我不需要用于文件读/写操作的ItemWriter和ItemReader.因此,我可以从中删除 ItemReader ItemWriter 吗?

我的工作配置如下:

 <batch:job id="reportJob">
                 <batch:step id="step1">
                     <batch:tasklet>
    <!--I want to remove ItemReader and ItemWriter as its not used -->
                         <batch:chunk reader="ItemReader" writer="ItemWriter"
                            commit-interval="10">
                        </batch:chunk>
                    </batch:tasklet>
                </batch:step>

                <batch:listeners>
                    <batch:listener ref="simpleListener"/>
                </batch:listeners>
            </batch:job>

<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
            <!-- Cache Refresh code is written here : JobLauncherDetails.java file -->
        <property name="jobClass" value="com.mkyong.quartz.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="reportJob" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
                <entry key="param1" value="mkyong1" />
                <entry key="param2" value="mkyong2" />
            </map>
        </property>
    </bean>

我编写了业务逻辑以刷新JobClass JobLauncherDetails.java上的缓存.因此可以删除ItemReader和ItemWriter吗?我们有其他可能的替代方法吗?

解决方案

使用

<job id="reportJob">
  <step id="step1">
    <tasklet ref="MyTaskletBean" />
  </step>
  <!-- Other config... -->
</job>



class MyTasklet implements Tasklet {
  @Override
  public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
  }
}

您可以从官方文档

In my project, I have written a Quartz scheduler with Spring Batch 2.2.

As per my requirement, I want to run a scheduler to fetch application config property to refresh the configuration cache on all the GlassFish Clusters.

So I dont need ItemWriter and ItemReader which are used to for File Read/Write operations.So can I remove ItemReader and ItemWriter from ?

The configuration of my job is mentioned below :

 <batch:job id="reportJob">
                 <batch:step id="step1">
                     <batch:tasklet>
    <!--I want to remove ItemReader and ItemWriter as its not used -->
                         <batch:chunk reader="ItemReader" writer="ItemWriter"
                            commit-interval="10">
                        </batch:chunk>
                    </batch:tasklet>
                </batch:step>

                <batch:listeners>
                    <batch:listener ref="simpleListener"/>
                </batch:listeners>
            </batch:job>

<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
            <!-- Cache Refresh code is written here : JobLauncherDetails.java file -->
        <property name="jobClass" value="com.mkyong.quartz.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="reportJob" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
                <entry key="param1" value="mkyong1" />
                <entry key="param2" value="mkyong2" />
            </map>
        </property>
    </bean>

I writing my business logic to refresh cache on JobClass JobLauncherDetails.java.So is it possible to remove ItemReader and ItemWriter ? Do we have any possible alternative way ?

解决方案

Use a Tasklet

<job id="reportJob">
  <step id="step1">
    <tasklet ref="MyTaskletBean" />
  </step>
  <!-- Other config... -->
</job>



class MyTasklet implements Tasklet {
  @Override
  public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
  }
}

You can read more on Tasklet at chapter 5.2 from official doc

这篇关于我们可以在没有ItemReader和ItemWriter的情况下编写Spring Batch作业吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:58