Skip to content

Commit

Permalink
Create ItemReader with a builder
Browse files Browse the repository at this point in the history
  • Loading branch information
pkainulainen committed Dec 20, 2020
1 parent 9ce132d commit 6e53ce9
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.xml.StaxEventItemReader;
import org.springframework.batch.item.xml.builder.StaxEventItemReaderBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
Expand All @@ -23,15 +23,15 @@ public class SpringBatchExampleJobConfig {

@Bean
public ItemReader<StudentDTO> itemReader() {
StaxEventItemReader<StudentDTO> xmlFileReader = new StaxEventItemReader<>();
xmlFileReader.setResource(new ClassPathResource("data/students.xml"));
xmlFileReader.setFragmentRootElementName("student");

Jaxb2Marshaller studentMarshaller = new Jaxb2Marshaller();
studentMarshaller.setClassesToBeBound(StudentDTO.class);
xmlFileReader.setUnmarshaller(studentMarshaller);

return xmlFileReader;
return new StaxEventItemReaderBuilder<StudentDTO>()
.name("studentReader")
.resource(new ClassPathResource("data/students.xml"))
.addFragmentRootElements("student")
.unmarshaller(studentMarshaller)
.build();
}

@Bean
Expand Down

0 comments on commit 6e53ce9

Please sign in to comment.