How to get command line parameters into a spring batch job
13,387
You might consider changing your Item Reader from
<bean id="reader" class="com.xyz.reporting.TAReportItemReader">
to
<bean id="reader" class="com.xyz.reporting.TAReportItemReader" scope="step">
Related videos on Youtube
Comments
-
Joe Zitzelberger almost 2 years
I am using a CommandLineJobRunner to execute a spring batch job. I want to pass in a set of parameters, but I'm running into some problems. This is my step:
<bean id="loadTAReportsJob" class="org.springframework.batch.core.job.SimpleJob"> <property name="steps"> <bean id="loadStep" parent="simpleStep"> <property name="itemReader"> <bean id="reader" class="com.xyz.reporting.TAReportItemReader"> <property name="parm1" value="#{jobParameters['input.file']}" /> <property name="parm2" value="#{jobExecutionContext['input.file']}" /> <property name="parm3" value="#{stepExecutionContext['input.file']}" /> </bean> </property> <property name="itemWriter"> <bean id="writer" class="com.xyz.reporting.TAReportItemWriter"> <property name="reportDomainFacade" ref="reportDomainFacade"/> </bean> </property> </bean> </property> <property name="jobRepository" ref="jobRepository"/> </bean>
The CommandLineJobRunner reports that:
2407 [P=717580:O=0:CT] INFO support.SimpleJobLauncher - Job: [SimpleJob: [name=loadTAReportsJob]] launched with the following parameters: [{input.file=somefile.zip}{}{}{}]
But in my ReportItemReader, the three parms all resolve to the full value:
#{jobParameters['input.file']} #{jobExecutionContext['input.file']} #{stepExecutionContext['input.file']}
That is, spring batch doesn't seem to be resolving the #{JobXYZ['parm name'].
Do I have to do something special to make spring resolve that syntax and do the property lookup? Do I need to wire up a JobParameters object or something to make this thing work?
BTW - I'm using Spring Batch 1.1.4 to keep compat with java 1.4.2.
-
Joe Zitzelberger about 13 yearsI did do this, but I'm still not getting the #{} syntax resolved. Do I need to do something special to wire up the job or step execution context?
-
Joe Zitzelberger about 13 yearsThanks for pointing me in the right direction. Under 1.1.4 I needed to use a StepExecutionResourceProxy and wire it up to listen to the step.
-
Diego Magalhães over 12 yearsJoe, could you please provide insight over the code? I'm trying to get dynamic SQL on no <property name="sql"> but no success.