Announcement Announcement Module
Collapse
No announcement yet.
ClassCastException: $Proxy9 to MultiResourceItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassCastException: $Proxy9 to MultiResourceItemReader

    Hi,
    Since i upgraded my application from org.springframework.batch.core-2.0.0.M4.jar to spring-batch-infrastructure-2.1.5.RELEASE.jar i am getting runtime exception as
    Code:
    [DEBUG] [] [InterfaceJobScheduler_Worker-1] org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:402) - Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
    [DEBUG] [] [InterfaceJobScheduler_Worker-1] org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:436) - Rollback for RuntimeException: java.lang.ClassCastException: $Proxy9 cannot be cast to org.springframework.batch.item.file.MultiResourceItemReader
    [DEBUG] [] [InterfaceJobScheduler_Worker-1] org.springframework.batch.repeat.support.RepeatTemplate.doHandle(RepeatTemplate.java:291) - Handling exception: java.lang.ClassCastException, caused by: java.lang.ClassCastException: $Proxy9 cannot be cast to org.springframework.batch.item.file.MultiResourceItemReader
    [DEBUG] [] [InterfaceJobScheduler_Worker-1] org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:251) - Handling fatal exception explicitly (rethrowing first of 1): java.lang.ClassCastException: $Proxy9 cannot be cast to org.springframework.batch.item.file.MultiResourceItemReader
    [ERROR] [] [InterfaceJobScheduler_Worker-1] org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:212) - Encountered an error executing the step
    java.lang.ClassCastException: $Proxy9 cannot be cast to org.springframework.batch.item.file.MultiResourceItemReader
    	at com.applied.fincrm.common.FileConverter.execute(FileConverter.java:419)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:371)
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:262)
    	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)



    My job file looks like
    Code:
    <step id="ReadAndUploadBLDFile" next="ReadAndUploadTRNFile" parent="skipLimitStep">
          <tasklet>
    	<chunk reader="BLDItemReader" processor="masterProcessor" writer="masterItemWriter" commit-interval="10" skip-limit="10">
       	             <skippable-exception-classes>					
    	 		<include class="org.springframework.batch.item.validator.ValidationException"/> 	                   
    		</skippable-exception-classes>
    	</chunk>
    	<listeners>
    	            <listener ref="masterListener"/>			
    	</listeners>
         </tasklet>						
    </step>		
    <bean id="BLDItemReader" class="org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
    	<property name="delegate" ref="BLDDelegateReader"/>
    </bean>	
    <bean id="BLDDelegateReader" class="org.springframework.batch.item.file.FlatFileItemReader">
    	<property name="lineMapper">
    	         <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
    			<property name="lineTokenizer" ref="compositeLineTokenizer"/>
    			<property name="fieldSetMapper" ref="compositeFieldSetMapper"/>
    	        </bean>
    	 </property>
    	<property name="comments" value="HDR,;" />
     </bean>
     <bean id="springApplicationContext" class="com.applied.fincrm.common.SpringApplicationContext"/>
    my requirement is, i have some files in my specified directory,
    CS061907.BLD
    CS062007.BLD
    CS062107.BLD
    among this file i want to process file based on date criteria.
    in short i want to setResourse from tasklet dynemically from Tasklet

    Code:
    	public class FileConverter implements Tasklet 
      {
        private Resource[] resourcesBLD;
        public RepeatStatus execute(StepContribution arg0, ChunkContext chunkContext) throws Exception
        {
            // some code to fill Resource[] 
            MultiResourceItemReader m = (MultiResourceItemReader) SpringApplicationContext.getBean("BLDItemReader");
            m.setResources(resourcesBLD);
        }
      }
    This code was working till i used org.springframework.batch.core-2.0.0.M4.jar version

    Please sugegst solution !
    Last edited by rajeshgajipara; Jan 21st, 2011, 07:49 AM.

  • #2
    Step scope uses JDK proxies by default. You can use CGLib to generate the proxy by setting proxy-target-class="true" on a bean definition for StepScope. That should work, but it would be better probably to use regular late binding somehow, or Spring EL (if you are using Spring 3). Instead of saving a reference to the ItemReader in your tasklet use an expression to set the resources in the reader (it will only be evaluated when needed).

    Comment

    Working...
    X