Reputation: 1738
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;
}
Upvotes: 2
Views: 8348
Reputation: 21483
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
Upvotes: 6