Announcement Announcement Module
Collapse
No announcement yet.
Problem using scope="step" with MultiResourceItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using scope="step" with MultiResourceItemReader

    I am using Spring 2.5 + Spring Batch 2.0.2. I am using MRIR for reading data from multiple files which are placed in working folder by steps executed before load step
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:batch="http://www.springframework.org/schema/batch"
    	xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    
    
    	<import resource="../../applicationcontext.xml" />
    	<import resource="F2DBeans.xml" />
    	
    
    	<batch:job id="F2D" job-repository="simpleJobRepository"
    		restartable="true">
    
    		<batch:step id="copyToStage" next="copyToProcess" parent="simpleStep">
    			<batch:tasklet ref="copyToStageTasklet" />
    		</batch:step>
    
    		<batch:step id="copyToProcess" next="loadFile" parent="simpleStep">
    			<batch:tasklet ref="copyToProcessTasklet" />
    		</batch:step>
    
    		<batch:step id="loadFile" next="moveToArchieve" parent="simpleStep">
    			<batch:tasklet transaction-manager="transactionManager">
    				<batch:chunk reader="itemReader" writer="consoleWritter"
    					commit-interval="1" />
    			</batch:tasklet>
    		</batch:step>
    
    		<batch:step id="moveToArchieve" next="purgeStep" parent="simpleStep">
    			<batch:tasklet ref="moveToArchiveTasklet" />
    		</batch:step>
    
    		<batch:step id="purgeStep" parent="simpleStep">
    			<batch:tasklet ref="purgeTasklet" />
    		</batch:step>
    	</batch:job>
    
    	<bean id="itemWriter" parent="databaseWriter">
    		<property name="statementId" value="${batchConfig.iBATIS.insertQuery}" />
    	</bean>
    	
    	<bean id="itemReader" 
    		class="org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
    		<property name="resources" value="file:data/working/*" />
    		<property name="delegate" ref="fileReader" />
    
    	</bean>
    
    	<bean id="consoleWritter" class="com.jpmc.cco.cdt.ConsoleWritter" />
    
    	<bean id="fileReader" class="org.springframework.batch.item.file.FlatFileItemReader">
    		<property name="lineMapper" ref="mapper" />
    	</bean>
    
    	<bean id="mapper"
    		class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
    		<property name="lineTokenizer" ref="tokenizer" />
    		<property name="fieldSetMapper" ref="genricFieldSetMapper" />
    	</bean>
    
    	<bean id="tokenizer"
    		class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
    		<property name="delimiter" value="|" />
    		<property name="names" value="DATA,CARD_NB,OFR_ID" />
    	</bean>
    </beans>
    When i am running above job i get following error -
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'F2D': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.SimpleFlow] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [6]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6': Cannot resolve reference to bean 'loadFile' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadFile': Initialization of bean failed; nested exception is java.lang.IllegalStateException: No Scope registered for scope 'step'
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at com.jpmc.cco.cdt.core.BatchMain.doWork(BatchMain.java:107)
    	at com.chase.ccs.common.AbstractBatch.doWork(AbstractBatch.java:209)
    	at com.chase.ccs.common.AbstractBatch.execute(AbstractBatch.java:93)
    	at com.jpmc.cco.cdt.core.BatchMain.main(BatchMain.java:45)
    If i remove the scope="step" MRIR defination, job runs successfully but do not load any file as when job is loaded the working folder is empty.

    Is it problem with jars I am using or there is issue with beans defination?

  • #2
    Try adding

    Code:
    <bean class="org.springframework.batch.core.scope.StepScope" />
    to your configuration file. See also
    http://static.springsource.org/sprin...tml#step-scope

    Comment


    • #3
      I tried that, but no luck!

      Comment


      • #4
        Well, that should work. Where have you added the configuration?

        Comment


        • #5
          I have delcared it in F2DBeans.xml which is imported in my job configuration.
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
          	xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          	xsi:schemaLocation="
                  http://www.springframework.org/schema/beans 
                  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
                  
                  <bean class="org.springframework.batch.core.scope.StepScope" />
          
          	<bean id="copyToStageTasklet" class="com.jpmc.cco.cdt.core.tasklet.file.FileCopyTasklet">
          		<property name="source" value="${batchConfig.landingPad}" />
          		<property name="destination" value="${batchConfig.staging}" />
          		<property name="fileManagement" ref="fileManagement"/>
          	</bean>
          ............
          As mentioned in documentation http://static.springsource.org/sprin...tml#step-scope I can not add in job configuration directly as i am importing batch.xsd.

          Comment


          • #6
            Try using this xsd: http://www.springframework.org/schem...-batch-2.1.xsd

            Comment


            • #7
              Its working now as expected. The problem was the way job was loaded. I used XML bean factory instead of application context to load the beans. After changing to application context the job is working fine with step scope.

              Comment


              • #8
                Spring Batch and MultiFolder Access.

                Hi
                I am facing issue w.r.t Multifolder access.
                My req. is I need to access/read of each files(in difrrent format like .txt, .rdy and .tiff images) from a sub folder(B) inside Main Folder(A) using Spring Batch configuration file.(MultiResourceItemReader).
                CAn any one help on this issue.

                Comment

                Working...
                X