mongodb - Spring Batch reader file by file -
i'm developing spring webapp, using spring boot , spring batch frameworks.
we have set of complex & different json files, , need to:
- read each file
- slightly modify content
- finally store them in mongodb.
the question: makes sense use spring batch task? can see in tutorials examples etc, spring batch right tool line line processing, file file?
i don't have problems writer (mongoitemwritter) , processer, not see how implement reader.
thanks!
yes can definetly use spring batch. item reader can file.
public class customitemreader implements initializingbean{ private list<file> yourfiles= null; public file read() { if ((yourfiles!= null) && (yourfiles.size() != 0)) { return yourfiles.remove(0); } return null; } //reading items service private void reloaditems() { this.youritems= new arraylist<file>(); // populate items } @override public void afterpropertiesset() throws exception { reloaditems(); } } a custom processor :
public class myprocessor implements itemprocessor<file, file> { @override public file process(file arg0) throws exception { // apply logic file before transferring writer return arg0; } } and custom writer :
public class mywriter{ public void write(file file) throws ioexception { } }
Comments
Post a Comment