Mar*_*cek 2 java spring classpath spring-batch
我想调整我的代码,使其Spring Batch reader不是从类路径读取资源文件,而是从文件系统(如C:\ inputData.xml)读取资源文件.有什么办法,怎么做?我当前的代码看起来像这样,并xml从资源文件夹中读取给定的文件就好了:
@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;
}
Run Code Online (Sandbox Code Playgroud)
将您更改ClassPathResource为a FileSystemResource并传入路径.您可以FileSystemResource在此处阅读有关文档的更多信息:http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/io/FileSystemResource.html
| 归档时间: |
|
| 查看次数: |
4395 次 |
| 最近记录: |