Announcement Announcement Module
Collapse
No announcement yet.
IllegalStateException: No context holder available for step scope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalStateException: No context holder available for step scope

    I have XML-based beans defined as

    Code:
    <bean class = "org.springframework.batch.core.scope.StepScope"/>
    
    <bean id = "genericStep" class = "org.springframework.batch.core.step.item.SimpleStepFactoryBean" abstract = "true">
    ...
    
    <bean id = "myStep" parent = "genericStep" scope = "step">
    ...
    When the application context is loaded, I get the following exception.

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.myStep': 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.doGetBean(AbstractBeanFactory.java:339)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:182)
    	at $Proxy18.getName(Unknown Source)
    	at org.springframework.batch.core.job.flow.support.state.StepState.<init>(StepState.java:40)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
    	... 87 more
    Caused by: java.lang.IllegalStateException: No context holder available for step scope
    	at org.springframework.batch.core.scope.StepScope.getContext(StepScope.java:197)
    	at org.springframework.batch.core.scope.StepScope.get(StepScope.java:139)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
    So it appears that the system expects the bean to be a prototype, which makes sense. But I can't figure out how to force that. I tried configuring SimpleStepFactoryBean to have singleton=true. That didn't work.

    Anyone have suggestions? Thanks.

  • #2
    In case it helps, the job containing this step, defined in a separate XML file, is configured as

    Code:
    <job id = "standard" parent = "defaultJob">
        <flow id = "standard-flow" parent = "standardFlow"/>
    </job>
    
    <flow id = "standardFlow" abstract = "true">
        <step id = "standardOutput" parent = "myStep">
            <fail on = "FAILED" exit-code = "1"/>
            <end on = "*"/>
        </step>
    </flow>
    
    <job id = "defaultJob" abstract = "true" incrementer = "parametersIncrementer">
        <listeners>
            <listener ref = "jobExecutionListener"/>
        </listeners>
    </job>

    Comment


    • #3
      A Step is not allowed to have scope="step" (the context for the scope is created by the step itself).

      Comment


      • #4
        Duh. [palm smacking forehead]. That was dumb of me. Sometimes you get too close. Trees and forest. Anyway, thanks.

        Comment

        Working...
        X