Results 1 to 4 of 4

Thread: IllegalStateException: No context holder available for step scope

  1. #1
    Join Date
    Oct 2004
    Location
    San Diego, CA USA
    Posts
    58

    Default 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. #2
    Join Date
    Oct 2004
    Location
    San Diego, CA USA
    Posts
    58

    Default

    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>

  3. #3
    Join Date
    Jun 2005
    Posts
    4,230

    Default

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

  4. #4
    Join Date
    Oct 2004
    Location
    San Diego, CA USA
    Posts
    58

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •