0

我已经ResourceAware在我的域对象中实现了在使用MultiResourceItemReader. 我成功地检索到处理器中的资源名称。但是,我无法访问其中的资源名称,FlatFileItemWriter因为在使用ClassifierCompositeItemWriter. 任何帮助将非常感激。

配置

 stepBuilderFactory.get("enrichmentStep")
.<RecordType, RecordType>chunk(1)
.reader(multiResourceItemReader())
.processor(processor())
.writer(compositeWriter())
.stream(type0Writer())
.stream(type1Writer())
.stream(type2Writer())

作家

public ClassifierCompositeItemWriter compositeWriter() throws Exception {
  ClassifierCompositeItemWriter<RecordType> writer = new ClassifierCompositeItemWriter<>();
  SubclassClassifier classifier = new SubclassClassifier<>();
  Map typeMap = new HashMap<>();
  typeMap.put(RecordType0.class, type0Writer());
  typeMap.put(RecordType1.class, type1Writer());
  typeMap.put(RecordType2.class, type2Writer());
  classifier.setTypeMap(typeMap);
  writer.setClassifier(classifier);
  return writer;
}

@Bean
public FlatFileItemWriter<RecordType0> type0Writer() throws Exception{
  FlatFileItemWriter<RecordType0> writer = new FlatFileItemWriter<>();
  writer.setResource( new FileSystemResource("")); //To get the resource value from domain object here
  writer.setAppendAllowed(true);
  writer.setLineAggregator(new DelimitedLineAggregator<RecordType0>() {{
  setDelimiter("#");
  setFieldExtractor(new BeanWrapperFieldExtractor<RecordType0>() {{
  setNames(new String[] { "RecordType", "BatchID", "SubBatchID"});}});}});
   return  writer;
}
4

0 回答 0