Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们可以在没有ItemReader和ItemWriter的情况下编写Spring批处理作业吗_Spring_Spring Batch - Fatal编程技术网

我们可以在没有ItemReader和ItemWriter的情况下编写Spring批处理作业吗

我们可以在没有ItemReader和ItemWriter的情况下编写Spring批处理作业吗,spring,spring-batch,Spring,Spring Batch,在我的项目中,我用SpringBatch 2.2编写了一个Quartz调度器 根据我的要求,我想运行一个调度程序来获取应用程序配置属性,以刷新所有GlassFish集群上的配置缓存 所以我不需要ItemWriter和ItemReader,它们用于文件读/写操作。 那么我可以从中删除ItemReader和itemrwriter吗 我的作业的配置如下所述: <batch:job id="reportJob"> <batch:step id="st

在我的项目中,我用SpringBatch 2.2编写了一个Quartz调度器

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

所以我不需要ItemWriter和ItemReader,它们用于文件读/写操作。 那么我可以从中删除ItemReaderitemrwriter

我的作业的配置如下所述:

 <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?我们有没有其他可行的方法?

使用


类MyTasklet实现了Tasklet{
@凌驾
public RepeatStatus execute(StepContribution贡献,ChunkContext ChunkContext)引发异常{
}
}

您可以在第5.2章中阅读更多关于Tasklet的内容,请访问

感谢bellabax的回复。创建新的Tasklet bean对我来说很有效。但我在某处看到,对于ItemReader、ItemProcessor和ItemProcessor,我们可以定义三个独立的步骤,如。。步骤1将读取文件,步骤2将处理文件,步骤3将写入文件。所以我们不需要创建tasklet和chunk。几年前,我在春天的某个地方看到了同样的发展。如果可能的话,请告诉我?我们是否可以删除tasklet和chunk,并为itemreading、itemprocessing和itemwriting编写单独的步骤?我不这么认为,因为读写器是强制性的(以及完成策略和提交间隔之间的一个步骤)。。它可能是一些旧版本的Spring Batch或其他东西。谢谢你能看一下吗?
<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 {
  }
}