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
Similar code has been working when I am using 1.0m4Code:org.springframework.batch.io.exception.BatchCriticalException: org.springframework.beans.factory.BeanCreationException: 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
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):
My unit testCode:<!-- 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>
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.Code:@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); } }
Exception is thrown during jobLauncher.run(job,jobParam);
Code:2008-02-21 19:26:01,645 INFO [org.springframework.batch.execution.launch.SimpleJobLauncher] - <Job: [SimpleJob: [name=job]] failed with the following parameters: [{KEY=1}{}{}]> org.springframework.batch.io.exception.BatchCriticalException: org.springframework.beans.factory.BeanCreationException: 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.TaskletStep.execute(TaskletStep.java:134) at org.springframework.batch.execution.job.simple.SimpleJob.execute(SimpleJob.java:88) at org.springframework.batch.execution.launch.SimpleJobLauncher$1.run(SimpleJobLauncher.java:85) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) at org.springframework.batch.execution.launch.SimpleJobLauncher.run(SimpleJobLauncher.java:80) at foo.sample.TradeMatchBatchTests.testLaunchJob(TradeMatchBatchTests.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:198) at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:274) at org.springframework.test.context.junit4.SpringMethodRoadie$2.run(SpringMethodRoadie.java:207) at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:254) at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:234) at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:204) at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:146) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:151) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.springframework.beans.factory.BeanCreationException: 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.AbstractBeanFactory.getBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170) at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget(Cglib2AopProxy.java:662) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:612) at foo.sample.TradeMatchTasklet$$EnhancerByCGLIB$$f5e84820.execute(<generated>) at org.springframework.batch.execution.step.tasklet.TaskletStep$1.doInIteration(TaskletStep.java:124) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:324) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:201) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:131) at org.springframework.batch.execution.step.tasklet.TaskletStep.execute(TaskletStep.java:122) ... 28 more Caused by: java.lang.IllegalStateException: No context holder available for step scope at org.springframework.batch.execution.scope.StepScope.getContext(StepScope.java:127) at org.springframework.batch.execution.scope.StepScope.get(StepScope.java:68) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:285) ... 38 more
What may cause such problem?
unit tests in the sample project is running fine


Reply With Quote