Results 1 to 4 of 4

Thread: Problem in MultiResourceItemReader

  1. #1

    Post Problem in MultiResourceItemReader

    Hi,
    I have Spring Batch which need to read files from one folder and insert into Database and moved the files into Archive Directory and it should run every 10 minutes becouse my requirement is that every 5 minutes more files are going to be dropped to that directory.
    I am running through Quartz and in very first time Batch is running sucessfully but subsequent time it is not reading files from that directory though more files came in mean time.
    Pls . help me.

    Code:
    import resource="classpath:codeServiceContext.xml" />
    
    	<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    		<property name="databaseType" value="${jdbc.databasetype}" />   
            <property name="dataSource" ref="dataSourceDB2T" />
            <property name="tablePrefix" value="${jdbc.table_prefix}" />
    		<property name="transactionManager" ref="transactionManager" />
    	</bean>
    
    	<bean id="mapJobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" 
    		p:transactionManager-ref="transactionManager" lazy-init="true" autowire-candidate="false" />
    
    	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    		<property name="dataSource" ref="dataSourceDB2" />
    	</bean>
    
    	<bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="restartable" value="true" />
    	</bean>
    
    	<bean id="taskletStep" class="org.springframework.batch.core.step.tasklet.TaskletStep" abstract="true">
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="allowStartIfComplete" value="true" />
    	</bean>
    
    	<bean id="simpleStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"
    		abstract="true">
    		<property name="transactionManager" ref="transactionManager" />
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="startLimit" value="100" />
    		<property name="commitInterval" value="1" />
    	</bean>
    	
    	<bean id="skipLimitStep" class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean"
    		parent="simpleStep" abstract="true">
    		<property name="skipLimit" value="5" />
    	</bean>
    
    	<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    		<property name="customEditors">
    			<map>
    				<entry key="int[]">
    					<bean class="org.springframework.batch.support.IntArrayPropertyEditor" />
    				</entry>
    				<entry key="org.springframework.batch.item.file.transform.Range[]">
    					<bean class="org.springframework.batch.item.file.transform.RangeArrayPropertyEditor" />
    				</entry>
    				<entry key="java.util.Date">
    					<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
    						<constructor-arg>
    							<bean class="java.text.SimpleDateFormat">
    								<constructor-arg value="yyyyMMdd" />
    							</bean>
    						</constructor-arg>
    						<constructor-arg value="false" />
    					</bean>
    				</entry>
    			</map>
    		</property>
    	</bean>
    	
    	<!--<bean id="logAdvice" class="org.springframework.batch.sample.advice.ProcessorLogAdvice" />
    
    	<bean id="eventAdvice" class="org.springframework.batch.sample.advice.StepExecutionApplicationEventAdvice" />
    
    
    	--><bean id="multiResourceJob" parent="simpleJob">
    		<property name="steps">
    			<bean id="step1" parent="simpleStep" p:commitInterval="3">
    				<property name="streams" ref="fileItemReader" />
    				<property name="itemReader">
    					<bean
    						class="org.springframework.batch.item.validator.ValidatingItemReader">
    						<property name="validator" ref="fixedValidator" />
    						<property name="itemReader"
    							ref="fileItemReader" />
    					</bean>
    				</property>
    				<property name="itemWriter">
    					<bean
    						class="us.tn.state.trust.batch.emissions.writer.EmissionWriter">
    						<property name="emissionDao" ref="emissionDao" />
    					</bean>
    				</property>
    			</bean>
    		</property>
    	</bean>
    
    	<!-- INFRASTRUCTURE SETUP -->
    
    	<!-- This input source is injected into the test case to verify the output - not used by the job at all -->
    	<bean id="testItemReader"
    		class="org.springframework.batch.item.file.MultiResourceItemReader">
    		<property name="resources"
    			value="file:C:/ESPH/temp/*.act" />
    		<property name="delegate" ref="flatFileItemReader" />
    	</bean>
    	
    	<bean id="fileItemReader" parent="testItemReader"
    		autowire-candidate="false" />
    	
    	<bean id="flatFileItemReader"
    		class="org.springframework.batch.item.file.FlatFileItemReader">
    		<property name="resource"
    			value="file:C:/ESPH/test/etest_oreg_20100331_1351.act" />
    		<property name="lineTokenizer" ref="fixedFileTokenizer" />
    		<property name="fieldSetMapper" ref="fieldSetMapper" />
    	</bean>
    
    	<bean id="fixedFileTokenizer"
    		class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
    	<property name="names"
    			value="     inspTmstmp, emssnTststnNbr,  emssnTststnUnit,   fnlInspRslt, inspVin,    emssnTststnCnty, certSerl, cmplyCertExtn" />
    		<property name="columns"
    			value="   1-20,       21-22,           23-24,             25-25,       26-50,       95-96,          99-114,   159-159" />
    	</bean>
    		
    	<bean id="fixedValidator"
    		class="org.springframework.batch.item.validator.SpringValidator">
    		<property name="validator">
    			<bean id="tradeValidator"
    				class="org.springmodules.validation.valang.ValangValidator">
    				<property name="valang">
    					<value>
    						<![CDATA[
    						{ id.inspVin : length(?) <21 : 'ISIN too long' : 'isin_length' : 20}
    					]]>
    					</value>
    				</property>
    			</bean>
    		</property>
    	</bean>
    	<bean id="emissionDao"
    		class="us.tn.state.trust.batch.emissions.dao.EmissionDAO">
    		<property name="dataSource" ref="dataSourceDB2" />
    	</bean>
    
    	<bean id="fieldSetMapper"
    		class="us.tn.state.trust.batch.emissions.dao.mapper.EmissionFieldSetMapper" >
    		<property name="codeService" ref="codeService" />
    		</bean>
    I found the problem, the resources properties in MultiResourceItemReader initiates first time and second time it is trying to read the same files and not able to read the new files but not sure how to set resources at run time so that it should read the files whatever there that time.
    Last edited by adish1234; Apr 1st, 2010 at 02:35 PM.

  2. #2

    Default

    you are missing the scope="step" on your reader. If you don't set it, your bean is a standard Spring singleton and will be shared by every executions of your job.

  3. #3

    Default

    Quote Originally Posted by snicoll View Post
    you are missing the scope="step" on your reader. If you don't set it, your bean is a standard Spring singleton and will be shared by every executions of your job.
    Thanks a lot for your reply.
    I am using Spring Batch 1.1.3 version and org.springframework.batch.core.scope.StepScope is not there in Spring Batch 1.1.3 . Please let me know if any other option.

  4. #4

    Default

    Is there any reason you are using an older version. 2.1.0 has been released early this year.

    I don't know about older version of Spring batch actually so I am afraid I can't help

Posting Permissions

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