001/* 002 * Copyright 2012-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.sample.config; 017 018import org.springframework.batch.core.Job; 019import org.springframework.batch.core.Step; 020import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; 021import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; 022import org.springframework.batch.item.ItemReader; 023import org.springframework.batch.item.ItemWriter; 024import org.springframework.batch.sample.domain.trade.Trade; 025import org.springframework.batch.sample.domain.trade.internal.GeneratingTradeItemReader; 026import org.springframework.batch.sample.support.RetrySampleItemWriter; 027import org.springframework.beans.factory.annotation.Autowired; 028import org.springframework.context.annotation.Bean; 029import org.springframework.context.annotation.Configuration; 030 031/** 032 * @author Dave Syer 033 * 034 */ 035@Configuration 036public class RetrySampleConfiguration { 037 038 @Autowired 039 private JobBuilderFactory jobs; 040 041 @Autowired 042 private StepBuilderFactory steps; 043 044 @Bean 045 public Job retrySample() { 046 return jobs.get("retrySample").start(step()).build(); 047 } 048 049 @Bean 050 protected Step step() { 051 return steps.get("step").<Trade, Object> chunk(1).reader(reader()).writer(writer()).faultTolerant() 052 .retry(Exception.class).retryLimit(3).build(); 053 } 054 055 @Bean 056 protected ItemReader<Trade> reader() { 057 GeneratingTradeItemReader reader = new GeneratingTradeItemReader(); 058 reader.setLimit(10); 059 return reader; 060 } 061 062 @Bean 063 protected ItemWriter<Object> writer() { 064 return new RetrySampleItemWriter<Object>(); 065 } 066}