spring-batch

How to create a generic FlatFileItemReader to read CSV files with different headers?

℡╲_俬逩灬. 提交于 2020-12-26 04:36:09
问题 I'm creating a job that will read and process different .csv files based on an input parameter. There are 3 different types of .csv files with different headers. I want to map each line of a file to a POJO using a generic FlatFileItemReader . Each type of file will have its own POJO implementation, and all "File Specific POJOs" are subclassed from an abstract GenericFilePOJO . A tasklet will first read the input parameter to decide which file type needs to be read, and construct a

Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart

北城以北 提交于 2020-12-25 04:47:30
问题 Spring Batch decider is going into forloop. I have below requirements. If Step1 execute, check decider() if "NO" then end Job, if "Yes" then execute Step2 , if Step2 is COMPLETED then execute decider() f "NO" then end Job, if "Yes" then execute Step3 . Any guidance how can we configure in the batch? 2020-12-08 11:41:11.473 INFO 16800 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1] step1 2020-12-08 11:41:11.493 INFO 16800 --- [ main] o.s.batch.core.step.AbstractStep

Spring Batch: datasource for Batch and datasource for step

六月ゝ 毕业季﹏ 提交于 2020-12-15 06:41:23
问题 I need to get access to two datasources: Spring batch repository: in memory H2 My step needs to get access to a mssql . I've seen several example over there about how to create a custom batch configurer . However, sometimes: implements BatchConfigurer extends DefaultBatchConfigurer Currently, my configuration files are: . ├── steps │ └── MssqlBatchConfigurationStep.java └── MainJobBatchConfiguration.java My step configuration is: @Configuration public class MssqlBatchConfigurationStep {

Multiple Writers in Spring Batch with different entities

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-15 05:51:13
问题 Initial code: Tasklet class was defined where there are 3 methods: class Tasklet{ doBeforeStep(){ //Records a retrieved from the table. } doExecute(){ //It opens the file and reads the file. //Does all the processing one by one and creates a 2 list of records to update into the database. } doAfterStep(){ //The 2 list of records(Entities) are saved into the 2 different tables database using its corresponding repository class. Example: RepositoryClass.saveall(List containing 105,000 records) /

Spring batch: JdbcPagingItemReader doesn't obtain page 1 onwards

余生长醉 提交于 2020-12-15 00:30:46
问题 Here my reader: @Bean public ItemReader<Unitat> itemReader(PagingQueryProvider queryProvider) { return new JdbcPagingItemReaderBuilder<Unitat>() .name("creditReader") .dataSource(this.dataSource) .queryProvider(queryProvider) .rowMapper(this.unitatMapper) .pageSize(2) .build(); } @Bean public SqlPagingQueryProviderFactoryBean queryProvider() { SqlPagingQueryProviderFactoryBean provider = new SqlPagingQueryProviderFactoryBean(); provider.setDataSource(this.dataSource); provider.setSelectClause

Spring batch: JdbcPagingItemReader doesn't obtain page 1 onwards

余生长醉 提交于 2020-12-15 00:29:26
问题 Here my reader: @Bean public ItemReader<Unitat> itemReader(PagingQueryProvider queryProvider) { return new JdbcPagingItemReaderBuilder<Unitat>() .name("creditReader") .dataSource(this.dataSource) .queryProvider(queryProvider) .rowMapper(this.unitatMapper) .pageSize(2) .build(); } @Bean public SqlPagingQueryProviderFactoryBean queryProvider() { SqlPagingQueryProviderFactoryBean provider = new SqlPagingQueryProviderFactoryBean(); provider.setDataSource(this.dataSource); provider.setSelectClause

How to call appropriate Item Processor for different records?

江枫思渺然 提交于 2020-12-04 05:21:53
问题 I have a flat file containing different records(header, record and footer) HR,... RD,... FR,... ItemReader @Bean @StepScope public FlatFileItemReader reader(@Value("#{jobParameters['inputFileName']}") String inputFileName) { FlatFileItemReader reader = new FlatFileItemReader(); reader.setResource(new FileSystemResource(inputFileName)); reader.setLineMapper(patternLineMapper()); return reader; } @Bean public LineMapper patternLineMapper() { PatternMatchingCompositeLineMapper patternLineMapper

How to call appropriate Item Processor for different records?

孤街浪徒 提交于 2020-12-04 05:16:50
问题 I have a flat file containing different records(header, record and footer) HR,... RD,... FR,... ItemReader @Bean @StepScope public FlatFileItemReader reader(@Value("#{jobParameters['inputFileName']}") String inputFileName) { FlatFileItemReader reader = new FlatFileItemReader(); reader.setResource(new FileSystemResource(inputFileName)); reader.setLineMapper(patternLineMapper()); return reader; } @Bean public LineMapper patternLineMapper() { PatternMatchingCompositeLineMapper patternLineMapper

How to call appropriate Item Processor for different records?

假装没事ソ 提交于 2020-12-04 05:15:37
问题 I have a flat file containing different records(header, record and footer) HR,... RD,... FR,... ItemReader @Bean @StepScope public FlatFileItemReader reader(@Value("#{jobParameters['inputFileName']}") String inputFileName) { FlatFileItemReader reader = new FlatFileItemReader(); reader.setResource(new FileSystemResource(inputFileName)); reader.setLineMapper(patternLineMapper()); return reader; } @Bean public LineMapper patternLineMapper() { PatternMatchingCompositeLineMapper patternLineMapper

Using Spring Batch to parse date from file into LocalDateTime

五迷三道 提交于 2020-12-03 00:14:22
问题 I'm trying to read a CSV file with dates with Spring Batch, but I am having trouble parsing a date into a LocalDateTime Object: Field error in object 'target' on field 'date': rejected value [2017-07-20 04:15:25.0]; codes [typeMismatch.target.date,typeMismatch.date,typeMismatch.java.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [target.date,date]; arguments []; default message [date]]; default message [Failed to convert