Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Usage example for BatchResourceFactoryBean

  1. #1
    Join Date
    Jan 2008
    Posts
    9

    Default Usage example for BatchResourceFactoryBean

    Hi,

    I am very interested in this project. I am watching results for a while. Now , I am trying to use spring-batch for new project in my company.

    I have successfuly install it, and run samples.

    But, I can not make BatchResourceFactoryBean to work. Can you provide configuration for fixedLengthImportJob?

    I tried with:

    <bean id="fileLocator"
    class="org.springframework.batch.execution.resourc e.BatchResourceFactoryBean"
    scope="step">
    <property name="rootDirectory" value="file://c/gsm2/data/inct" />
    <property name="filePattern" value="%BATCH_ROOT%/%JOB_NAME%" />
    <aop:scoped-proxy />
    </bean>

    The error I receive is:

    Error creating bean with name 'scopedTarget.fileLocator': 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

    Thanks in advance

  2. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    What version of spring are you using?

  3. #3
    Join Date
    Jan 2008
    Posts
    9

    Default

    Spring 2.5.1

  4. #4

    Default

    This usually occurs when you try to use a "step" scoped bean from within a singleton. Think about it this way. You have a singleton, so every time it is referenced the same object is returned. Initialization of that object (including resolution of its references) occurs only once, the first time it is needed. This means that there is no lifecycle "hook" at the beginning and end of the step lifecycle from the Spring framework's perspective. In order to resolve this, you need to define your bean as a scoped proxy using the <aop:scoped-proxy /> tag. This causes your bean to be defined as a Proxy whose invocation handler redirects all calls to the appropriate instance of the class for the step. This allows Spring to keep track of and update the bean according to the rules defined in the framework, and manage the bean's lifecycle appropriately (calling init-method, destroy-method, afterPropertiesSet() and destroy() at the appropriate times).

    I tried to make this explanation clear, potentially at the expense of being 100% technically accurate (someone else please feel free give a better technical explanation), but nonetheless using the scoped proxy tag should fix the issue for you. If it doesn't, post again and let me know.

  5. #5

    Default

    Apologies! I didn't see you already had the tag in your configuration. That's what I get for posting at 3:30am.

    Anyway, could you please post more of your configuration for context?

    Thanks

  6. #6
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    This might not be the same issue, but I noticed recently that you get this error if spring-aop.jar is not on your classpath. The error message is confusing so I raised an issue against Spring Core and it is fixed in 2.5.2.

  7. #7
    Join Date
    Jan 2008
    Posts
    9

    Default

    I have spring.jar in my classpath (ver 2.5.1). I have make a comparison od content of spring-jar and spring-aop.jar and it seems (I am not 100% sure) that all content of spring-aop.jar is in spring.jar.

    To reproduce error just replace:

    Code:
    <bean id="fileLocator"
    	class="org.springframework.core.io.ClassPathResource">
    	<constructor-arg type="java.lang.String"
    		value="data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
    </bean>
    whit this:

    Code:
    <bean id="fileLocator"
    	class="org.springframework.batch.execution.resource.BatchResourceFactoryBean"
    	scope="step">
    	<property name="rootDirectory" value="file://c/gsm2/data/inct" />
    	<property name="filePattern" value="%BATCH_ROOT%/%JOB_NAME%" />
    	<aop:scoped-proxy />
    </bean>
    in fixedLengthImportJob.xml, and run that job through BatchCommandLineLauncher

  8. #8

    Default

    What is your result if you use your configuration without the <aop:scoped-proxy /> tag. It seems to me you shouldn't need that bean to be a proxy since it is referenced from a "step"-scoped scoped proxy bean already. That is, assuming your job configuration as a whole is similar in that way to the fixedLengthImportJob.
    Last edited by dkaminsky; Jan 28th, 2008 at 03:59 AM. Reason: added caveat

  9. #9
    Join Date
    Jan 2008
    Posts
    9

    Default

    It is the same with <aop:scoped-proxy /> and tithout it.

    Could you reproduce error according to my instructions?

  10. #10
    Join Date
    Jan 2008
    Posts
    9

    Default

    Any suggestions? I am working hard to resolve this issue, but no progress...

Posting Permissions

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