Back Forum Reply New

Dynamic file name for FileItemRead

I am looking for a way to kick off a batch which has a filename as an input parameter.
the filename would be used by the FileItemReader to open the file and process it.

I have not found any good (for me) explanations about how to do it. I know that I should set the resource parameter of my file reader as follows:
lt;property name=quot;resourcequot;value=quot;/data/input/${file.name}quot; /gt;

but I still don't get how that works. Do I need to create a variable file.name in my parameter list?

Thanks

Xav

It's covered in Chapter 3 of the reference documentation:

sp...e.html#d0e1694

Please let me know if after reading the docs you are still having issues.  We're always trying to improve them.

Thanks.

I see the doc has improved a lot recently.

Xav

Hello.

The link is broken, and I couldn't find an explanation of how to use a batch parameter as a resource path (I end up using a custom laucher registering the
parameter as a System property, combined with a PropertyPlaceholderConfigurer).

You'll want to use late-binding:
sp...l#late-binding

Thank you.

I already try that syntax : Code:
lt;property name=quot;resourcequot; value=quot;#{jobParameters[input.file.name]}quot; /gt;
But I must be missing something, the el expression is not interpreted and I end up with something like : Code:
at org..batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:207)
at org..batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:254)
Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource [#{jobParameters[input.file.name]}]
at org..batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245)
at org..batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:108)
... 18 more
Maybe there's an additional configuration required to use this feature ?

Make sure that your lt;bean/gt; has scope=quot;stepquot;

It's working now, thank you very much !

Here's the final config :

Code:
lt;bean id=quot;theReaderquot; class=quot;org..batch.item.file.FlatFileItemReaderquot;gt;       lt;property name=quot;lineMapperquot;gt;...       lt;/propertygt;               lt;property name=quot;resourcequot;gt;lt;bean class=quot;org..core.io.FileSystemResourcequot; scope=quot;stepquot;gt;    lt;constructor-arg value=quot;#{jobParameters[inputfilename]}quot; /gt;lt;/beangt;       lt;/propertygt;   lt;/beangt;It might be useful to add this tip in the reference documentation.

Is there a process to submit a documentation update ?

The subsequent section in the document is about StepScope, but I agree it might be nice to put a note so that readers are aware that the next section applies to them.

All issues (including Documentation issues) should be logged in JIRA: browse/BATCH
¥
Back Forum Reply New