2

I'd like to adjust my code to make the Spring Batch reader to read the resource file not from class path, but from the file system (like C:\inputData.xml). Is there any way, how to make it? My current code looks like this and reads given xml file from resources folder just fine:

@Bean
ItemReader<FamilyBatchEntity> xmlFamilyFileItemReader() {
    StaxEventItemReader<FamilyBatchEntity> xmlFileReader = new StaxEventItemReader<>();
    xmlFileReader.setResource(new ClassPathResource("inputData.xml"));
    xmlFileReader.setFragmentRootElementName("Familiendetails");

    Jaxb2Marshaller insurantMarshaller = new Jaxb2Marshaller();
    insurantMarshaller.setClassesToBeBound(FamilyBatchEntity.class);
    xmlFileReader.setUnmarshaller(insurantMarshaller);

    return xmlFileReader;
}
Martin Dvoracek
  • 1,714
  • 6
  • 27
  • 55

1 Answers1

6

Change your ClassPathResource to a FileSystemResource and pass in the path. You can read more about the FileSystemResource in the documentation here: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/io/FileSystemResource.html

Michael Minella
  • 20,843
  • 4
  • 55
  • 67