How to write a spring batch step without an itemwriter

后端 未结 3 1123
太阳男子
太阳男子 2020-12-15 10:25

I am trying to configure a spring batch step without an item writer using below configuraion. However i get error saying that writer element has neither a \'writer\' attrib

相关标签:
3条回答
  • 2020-12-15 10:58

    I hope you got answer but I want to explain it for other readers, When we use chunk then usually we declare reader, processor and writer. In chunk reader and writer are mandatory and processor is optional. In your case if you don't need writer then u need to make a class which implements ItemWriter. Override write method and keep it blank. Now create a bean of writer class and pass it as reference of writer.

    <batch:step id="recordProcessingStep" >
            <batch:tasklet>
                <batch:chunk reader="fileReader" processor="recordProcessor"
                    writer="rocordWriter" commit-interval="1" />
            </batch:tasklet>
        </batch:step>
    

    Your writer class will look like .

    public class RecordWriter<T> implements ItemWriter<T> {
    @Override
    public void write(List<? extends T> items) throws Exception {
        // TODO Auto-generated method stub
    
    }
    

    }

    0 讨论(0)
  • 2020-12-15 11:00

    For chunk-based step reader and writer are mandatory.
    If you don't want a writer use a No-operation ItemWriter that does nothing.

    EDIT:
    A no-op implementation is an empty implementation of interface tha does...nothing!
    Just let your class implements desiderable inteface(s) with empty methods.

    No-op ItemWriter:

    public class NoOpItemWriter implements ItemWriter {
      void write(java.util.List<? extends T> items) throws java.lang.Exception {
        // no-op
      }
    }
    
    0 讨论(0)
  • 2020-12-15 11:14

    In maven repo you can find the framework "spring-batch-samples".
    In this framework you will find this Writer :

    org.springframework.batch.sample.support.DummyItemWriter
    
    0 讨论(0)
提交回复
热议问题