adrianshum
Feb 21st, 2008, 05:46 AM
Dear all,
Today I have checked-out and try the trunk version.
However when I run my own testing code snippet (by Junit testcase), it throws exception
org.springframework.batch.io.exception.BatchCritic alException: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.tradeTasklet': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
Similar code has been working when I am using 1.0m4
I just wonder if I did anything wrong.
I am using JUnit4 + related unit test utils in Spring 2.5; JDK 5
snippets of codes I am using:
Here is my app context (sample1-job.xml):
<!-- stuffs that copied from simple-container-definition.xml -->
<bean id="job" parent="simpleJob">
<property name="steps">
<list>
<bean id="step1" parent="taskletStep">
<property name="tasklet">
<bean id="tradeTasklet"
class="foo.sample.TradeMatchTasklet"
scope="step">
<aop:scoped-proxy />
<property name="status" value="9"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
My unit test
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration
@Transactional
@ContextConfiguration(locations={"/mysample/sample1-job.xml"})
public class TradeMatchBatchTests {
@Resource
JobLauncher jobLauncher;
@Resource
private Job job;
@Resource
MapJobRegistry jobConfigurationRegistry;
@Test
public void testLaunchJob() throws Exception {
Map<String, String> strParam = new HashMap<String, String>();
strParam.put("KEY", "1");
JobParameters jobParam = new JobParameters(strParam, new HashMap(), new HashMap());
JobExecution x = jobLauncher.run(job, jobParam);
}
}
I should have correctly registered the StepScope by creating the corresponding bean in app context, and my tasklet's scope is set to "step", with <aop:scoped-proxy /> already.
Exception is thrown during jobLauncher.run(job,jobParam);
2008-02-21 19:26:01,645 INFO [org.springframework.batch.execution.launch.SimpleJ obLauncher] - <Job: [SimpleJob: [name=job]] failed with the following parameters: [{KEY=1}{}{}]>
org.springframework.batch.io.exception.BatchCritic alException: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.tradeTasklet': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.batch.execution.step.tasklet.T askletStep.execute(TaskletStep.java:134)
at org.springframework.batch.execution.job.simple.Sim pleJob.execute(SimpleJob.java:88)
at org.springframework.batch.execution.launch.SimpleJ obLauncher$1.run(SimpleJobLauncher.java:85)
at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
at org.springframework.batch.execution.launch.SimpleJ obLauncher.run(SimpleJobLauncher.java:80)
at foo.sample.TradeMatchBatchTests.testLaunchJob(Trad eMatchBatchTests.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.test.context.junit4.SpringTest Method.invoke(SpringTestMethod.java:198)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runTestMethod(SpringMethodRoadie.java:274 )
at org.springframework.test.context.junit4.SpringMeth odRoadie$2.run(SpringMethodRoadie.java:207)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runBeforesThenTestThenAfters(SpringMethod Roadie.java:254)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runWithRepetitions(SpringMethodRoadie.jav a:234)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runTest(SpringMethodRoadie.java:204)
at org.springframework.test.context.junit4.SpringMeth odRoadie.run(SpringMethodRoadie.java:146)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.invokeTestMethod(SpringJUnit4ClassRu nner.java:151)
at org.junit.internal.runners.JUnit4ClassRunner.runMe thods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run (JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotec ted(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtecte d(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(J Unit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.tradeTasklet': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:170)
at org.springframework.aop.target.SimpleBeanTargetSou rce.getTarget(SimpleBeanTargetSource.java:33)
at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.getTarget(Cglib2AopProxy. java:662)
at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:612)
at foo.sample.TradeMatchTasklet$$EnhancerByCGLIB$$f5e 84820.execute(<generated>)
at org.springframework.batch.execution.step.tasklet.T askletStep$1.doInIteration(TaskletStep.java:124)
at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:324)
at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:201)
at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:131)
at org.springframework.batch.execution.step.tasklet.T askletStep.execute(TaskletStep.java:122)
... 28 more
Caused by: java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.batch.execution.scope.StepScop e.getContext(StepScope.java:127)
at org.springframework.batch.execution.scope.StepScop e.get(StepScope.java:68)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:285)
... 38 more
What may cause such problem?
unit tests in the sample project is running fine
Today I have checked-out and try the trunk version.
However when I run my own testing code snippet (by Junit testcase), it throws exception
org.springframework.batch.io.exception.BatchCritic alException: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.tradeTasklet': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
Similar code has been working when I am using 1.0m4
I just wonder if I did anything wrong.
I am using JUnit4 + related unit test utils in Spring 2.5; JDK 5
snippets of codes I am using:
Here is my app context (sample1-job.xml):
<!-- stuffs that copied from simple-container-definition.xml -->
<bean id="job" parent="simpleJob">
<property name="steps">
<list>
<bean id="step1" parent="taskletStep">
<property name="tasklet">
<bean id="tradeTasklet"
class="foo.sample.TradeMatchTasklet"
scope="step">
<aop:scoped-proxy />
<property name="status" value="9"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
My unit test
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration
@Transactional
@ContextConfiguration(locations={"/mysample/sample1-job.xml"})
public class TradeMatchBatchTests {
@Resource
JobLauncher jobLauncher;
@Resource
private Job job;
@Resource
MapJobRegistry jobConfigurationRegistry;
@Test
public void testLaunchJob() throws Exception {
Map<String, String> strParam = new HashMap<String, String>();
strParam.put("KEY", "1");
JobParameters jobParam = new JobParameters(strParam, new HashMap(), new HashMap());
JobExecution x = jobLauncher.run(job, jobParam);
}
}
I should have correctly registered the StepScope by creating the corresponding bean in app context, and my tasklet's scope is set to "step", with <aop:scoped-proxy /> already.
Exception is thrown during jobLauncher.run(job,jobParam);
2008-02-21 19:26:01,645 INFO [org.springframework.batch.execution.launch.SimpleJ obLauncher] - <Job: [SimpleJob: [name=job]] failed with the following parameters: [{KEY=1}{}{}]>
org.springframework.batch.io.exception.BatchCritic alException: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.tradeTasklet': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.batch.execution.step.tasklet.T askletStep.execute(TaskletStep.java:134)
at org.springframework.batch.execution.job.simple.Sim pleJob.execute(SimpleJob.java:88)
at org.springframework.batch.execution.launch.SimpleJ obLauncher$1.run(SimpleJobLauncher.java:85)
at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
at org.springframework.batch.execution.launch.SimpleJ obLauncher.run(SimpleJobLauncher.java:80)
at foo.sample.TradeMatchBatchTests.testLaunchJob(Trad eMatchBatchTests.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.test.context.junit4.SpringTest Method.invoke(SpringTestMethod.java:198)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runTestMethod(SpringMethodRoadie.java:274 )
at org.springframework.test.context.junit4.SpringMeth odRoadie$2.run(SpringMethodRoadie.java:207)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runBeforesThenTestThenAfters(SpringMethod Roadie.java:254)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runWithRepetitions(SpringMethodRoadie.jav a:234)
at org.springframework.test.context.junit4.SpringMeth odRoadie.runTest(SpringMethodRoadie.java:204)
at org.springframework.test.context.junit4.SpringMeth odRoadie.run(SpringMethodRoadie.java:146)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.invokeTestMethod(SpringJUnit4ClassRu nner.java:151)
at org.junit.internal.runners.JUnit4ClassRunner.runMe thods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run (JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotec ted(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtecte d(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(J Unit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.tradeTasklet': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:170)
at org.springframework.aop.target.SimpleBeanTargetSou rce.getTarget(SimpleBeanTargetSource.java:33)
at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.getTarget(Cglib2AopProxy. java:662)
at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:612)
at foo.sample.TradeMatchTasklet$$EnhancerByCGLIB$$f5e 84820.execute(<generated>)
at org.springframework.batch.execution.step.tasklet.T askletStep$1.doInIteration(TaskletStep.java:124)
at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:324)
at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:201)
at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:131)
at org.springframework.batch.execution.step.tasklet.T askletStep.execute(TaskletStep.java:122)
... 28 more
Caused by: java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.batch.execution.scope.StepScop e.getContext(StepScope.java:127)
at org.springframework.batch.execution.scope.StepScop e.get(StepScope.java:68)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:285)
... 38 more
What may cause such problem?
unit tests in the sample project is running fine