Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does the SpringBatch MultiResourcePartitioner not recognize jobParameters? More to the point, what to do about it?
    primarykey
    data
    text
    <p>It's a pretty straight forward setup. I have a file of potentially 5m records that I need to read and do some work with and then send to the db. The mechanics of processing and writing are not important. I need to be able to pass the path and file name [ /opt/etc/app/partner/input_file.csv ] into the process as a parameter. That's easy enough, add it to the JobParameters and give it to the JobLauncher.</p> <pre><code>JobParametersBuilder jpBuilder = new JobParametersBuilder() ; jpBuilder.addString("filePath", "/opt/etc/app/partner/input_file.csv") ; jobLauncher.run(job, jpBuilder.toJobParameters() ; </code></pre> <p>Done, now to make the context aware of it. Again simple matter of referencing jobParameters.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch" xsi:schemaLocation=" http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt; &lt;description&gt;PoC to demonstrate variable row content handling&lt;/description&gt; &lt;batch:job id="poc" job-repository="jobRepository" incrementer="runIdIncrementer" restartable="true"&gt; &lt;batch:step id="pocReadWriteStep"&gt; &lt;batch:partition step="step" partitioner="partitioner"&gt; &lt;batch:handler task-executor="taskExecutor"/&gt; &lt;/batch:partition&gt; &lt;/batch:step&gt; &lt;/batch:job&gt; &lt;batch:step id="step"&gt; &lt;batch:tasklet task-executor="taskExecutor" throttle-limit="20" transaction-manager="transactionManager" allow-start-if-complete="true"&gt; &lt;batch:transaction-attributes isolation="READ_UNCOMMITTED"/&gt; &lt;batch:chunk reader="reader" processor="processor" writer="writer" commit-interval="20"&gt; &lt;/batch:chunk&gt; &lt;/batch:tasklet&gt; &lt;/batch:step&gt; &lt;bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"&gt; &lt;property name="resource" value="file:#{jobParameters['filePath']}"/&gt; &lt;property name="lineMapper"&gt; &lt;bean class="org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper"&gt; &lt;property name="tokenizers"&gt; &lt;map&gt; &lt;entry key="*" value-ref="lineTokenizer"/&gt; &lt;/map&gt; &lt;/property&gt; &lt;property name="fieldSetMappers"&gt; &lt;map&gt; &lt;entry key="*" value-ref="fieldSetMapper"/&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="lineTokenizer" class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"/&gt; &lt;bean id="fieldSetMapper" class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper"/&gt; &lt;bean id="processor" class="com.verifi.springbatchpoc.PocProcessor"/&gt; &lt;bean id="writer" class="com.verifi.springbatchpoc.PocWriter"/&gt; &lt;bean id="runIdIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/&gt; &lt;bean id="partitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner"&gt; &lt;property name="resources" value="file:#{jobParameters['filePath']}"/&gt; &lt;/bean&gt; &lt;bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"&gt; &lt;property name="corePoolSize" value="20"/&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>Except that in the MultiResourcePartitioner it can't seem to recognize the reference to jobParameters. I can hard code the path and file name and it's quite happy, but that doesn't carry the mail for this implementation.</p> <p>Since I'm sure someone is going to ask, here's the stack trace from the error (well part of it anyway).</p> <pre><code> at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 46 more Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:207) at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:71) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52) at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:97) at org.springframework.expression.common.CompositeStringExpression.getValue(CompositeStringExpression.java:82) at org.springframework.expression.common.CompositeStringExpression.getValue(CompositeStringExpression.java:1) at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:138) ... 52 more </code></pre> <p>Thoughts, comments, suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload