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;
}

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.