Late binding and JobParameters
Hello,
i desperatlely trying to pass parameter to an itemReader througth JobParameters and a late binding, but can't make it work... even if it seems really easy
I'm using Spring-batch 2.1.8 and Spring-core 3.0.5
here is a part of my applicationContext-Ipc.xml:
Code:
<batch:job id="IpcJob">
<batch:step id="ipcFileHandler" >
<batch:tasklet>
<batch:chunk reader="ipcFileReader" processor="clientProcessor" writer="notificationIpcWriter" commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="ipcFileReader" scope="step" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="file:#{jobParameters['filename']}"/>
<property name="lineMapper" ref="lineMapper"/>
<property name="comments" value="#"/>
</bean>
.
.
.
and my test class:
Code:
@ContextConfiguration({"classpath:applicationContext-Ipc.xml","classpath:applicationContext-Ipc-conf-test.xml"})
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,StepScopeTestExecutionListener.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class IpcFileReaderTest {
@Autowired
private ItemReader<Client> ipcFileReader;
public StepExecution getStepExecution(){
StepExecution execution = MetaDataInstanceFactory.createStepExecution();
execution.getExecutionContext().putString("filename",System.getProperty("user.dir") + "/src/test/resources/OMC_File/OMC_Test_1.csv");
return execution;
}
@Test
public void testReader() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception{
Assert.assertNotNull(ipcFileReader.read());
}
I always get this exception
Code:
java.lang.IllegalStateException: Cannot bind to partial key %{jobParameters['filename']} in file:%{jobParameters['filename']}
If I remove the 'file:' i get a different exception, but i guess the root problem is the same:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lazyBindingProxy.ipcFileReader#sysinit' defined in class path resource [applicationContext-Ipc.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot bind to placeholder: jobParameters['filename']
Any ideas would be greatly appreciated !
Thx.