Spring Batch - Skip Record On Process

后端 未结 4 1073
再見小時候
再見小時候 2021-01-03 02:18

I wanted to skip some record on process.

what i have tried is, i have created custom exception and throw the exception when i want to skip the record and its calling

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 02:40

    when we return null in the process() method, it will filter the record and increase the filter count.

    @Transactional(propagation = Propagation.REQUIRED)
        @Override
        public SomeObject process(SomeObject someObject) throws Exception {
            if (some condition) {
                return null;
            }   
    }
    

    If We want to skip the record , throw an exception. This will skip the record and increase processSkipCount as well.

    @Transactional(propagation = Propagation.REQUIRED)
        @Override
        public SomeObject process(SomeObject someObject) throws Exception {
            if (some condition) {
                throw new Exception("invalid record");
            }   
    }
    

    Add this Exception to context file as well.

    
    
    
    

提交回复
热议问题