I am using a Spring batch application and want to use the latest binding for stepExecutionContext. I encountered problems resolving my error.
Below is my reader that has sql property using late binding:
<bean id="itemReader_S4_JPolicy" class="com.aegonusa.etl.readers.JDBCItemReader" scope="step"> <property name="jobParameters" ref="jobParameters" /> <property name="dataSource" ref="readDataSource" /> <property name="rowMapper"> <bean class="com.aegonusa.etl.readers.ResultSetRowMapper" scope="step" /> </property> <property name="sql" value="#{stepExecutionContext['readQuery']}"></property> </bean>
I set this property ('readQuery') in the following class:
The public class StepListener implements StepExecutionListener {
.... .... ....
@Override public void beforeStep(StepExecution execution) { String s = "select getdate(); StepSynchronizationManager.getContext().setAttribute("readQuery", s);
.....} .....}
Note that I can do late binding using jobParameters parameters. But using stepExecutionContext, I get the following exc. I tried a lot of forum posts but couldn't solve it:
Throwable occurred: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lazyBindingProxy.itemReader_S4_JPolicy#sysinit' defined in class path resource [Load_InforceToStage.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot bind to placeholder: stepExecutionContext['readQuery'] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(AccessController.java:224) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:302) at org.springframework.batch.core.scope.StepScope.get(StepScope.java:150) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.batch.core.scope.util.PlaceholderTargetSource.getTarget(PlaceholderTargetSource.java:185) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184) at $Proxy1.close(Unknown Source) at org.springframework.batch.item.support.CompositeItemStream.close(CompositeItemStream.java:83) at org.springframework.batch.core.step.item.ChunkMonitor.close(ChunkMonitor.java:99) at org.springframework.batch.item.support.CompositeItemStream.close(CompositeItemStream.java:83) at org.springframework.batch.core.step.tasklet.TaskletStep.close(TaskletStep.java:297) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:255) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) at com.ebsadm.lh.LHSHEDToStage.runJob(LHSHEDToStage.java:124) at com.ebsadm.lh.LHSHEDToStage.main(LHSHEDToStage.java:111) at com.ebdadm.lh.TestLHSHEDToStage.testInforceLoadToStage(TestLHSHEDToStage.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Called: java.lang.IllegalStateException: cannot communicate with the placeholder: stepExecutionContext ['readQuery'] on org.springframework.batch.core.scope.util.PlaceholderTargetSource $ 1.convertIfNecessary (PlaceholderTargetSource.java:140) on org.sbeing .factory.support.AbstractAutowireCapableBeanFactory.convertForProperty (AbstractAutowireCapableBeanFactory.java:1294) on org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues ββ(AbstractAutowireCapableBeanFactory.java:1250) on org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .populateBean (AbstractAutowireCapableBeanFactory.java:1010) on org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:472) ... 50 more
Please help.
source share