Announcement Announcement Module
Collapse
No announcement yet.
StepExecutionProxy - ItemWriter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • StepExecutionProxy - ItemWriter

    Hi,

    I have just started using the Spring Batch framework for output file generation. I want to dynamically generate the output file names so am using the StepExecutionProxy

    Here is my spring configurations for the job

    Code:
    	<bean id="fileOutputJob" parent="simpleJob">
    		<property name="name" value="fileOutput" />
    		<property name="steps">
    			<list>
    				<bean id="step" parent="simpleStep">
    					<property name="commitInterval" value="100" />
    					<property name="itemReader" ref="fileReader" />
    					<property name="itemWriter" ref="fileWriter"/>
    					<property name="listeners" ref="outputFile"/>
    				</bean>
    			</list>
    		</property>
    	</bean>
    Here is my configuration for the writer where I have injected the resource

    Code:
    	<bean
    		class="fcpb.integration.batch.writer.FileWriter"
    		id="fileWriter">
    		<property name="delegate">
    			<bean
    				class="org.springframework.batch.item.file.FlatFileItemWriter"
    				id="flatFileOutputSource">
    				<property name="resource" ref="outputFile" />
    				<property name="fieldSetCreator"
    					ref="fileOutputFieldSetCreator" />
    			</bean>
    		</property>
    	</bean>
    And here is my StepExecutorProxy defined

    Code:
    <bean id="outputFile" class="org.springframework.batch.core.resource.StepExecutionResourceProxy"/>
    Now, I use the default pattern available which uses the JOB + STEP parameters

    When I run the test case I get the following error. Any ideas. Does the output directory need to be present ? Thanks in advance

    Code:
    Caused by: java.io.FileNotFoundException: class path resource [data/fileOutputJob/step.txt] cannot be resolved to URL because it does not exist

  • #2
    What version of the framework are you using? I'm thinking there was a bug in 1.0 that got fixed in 1.0.1

    Comment


    • #3
      1.0.1.RELEASE is the version that I am using

      Comment


      • #4
        Can you send the full stack trace of the error? I'm curious which class is throwing it, it's definitely not the writer itself.

        Comment


        • #5
          Sure, here it is...btw the configuration is correct right coz there are no examples out there which depict this scenario !!

          Code:
          org.springframework.batch.item.ItemStreamException: Could not test resource for writable status.
          	at org.springframework.batch.item.file.FlatFileItemWriter.getOutputState(FlatFileItemWriter.java:236)
          	at org.springframework.batch.item.file.FlatFileItemWriter.flush(FlatFileItemWriter.java:509)
          	at fcpb.integration.batch.writer.OrderWriter.flush(OrderWriter.java:71)
          	at org.springframework.batch.item.support.DelegatingItemWriter.flush(DelegatingItemWriter.java:77)
          	at org.springframework.batch.core.step.item.SimpleItemHandler.flush(SimpleItemHandler.java:133)
          	at org.springframework.batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:256)
          	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:346)
          	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:212)
          	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
          	at org.springframework.batch.core.step.item.ItemOrientedStep.doExecute(ItemOrientedStep.java:219)
          	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:168)
          	at org.springframework.batch.core.job.SimpleJob.execute(SimpleJob.java:125)
          	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:86)
          	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
          	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:81)
          	at fcpb.integration.batch.AbstractBatchTestCase.testLaunchJob(AbstractBatchTestCase.java:60)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:597)
          	at junit.framework.TestCase.runTest(TestCase.java:154)
          	at junit.framework.TestCase.runBare(TestCase.java:127)
          	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
          	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.access$001(AbstractAnnotationAwareTransactionalTests.java:47)
          	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests$1.run(AbstractAnnotationAwareTransactionalTests.java:115)
          	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTest(AbstractAnnotationAwareTransactionalTests.java:180)
          	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runTestTimed(AbstractAnnotationAwareTransactionalTests.java:153)
          	at org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.runBare(AbstractAnnotationAwareTransactionalTests.java:111)
          	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:174)
          	at fcpb.integration.batch.AbstractBatchTestCase.runBare(AbstractBatchTestCase.java:70)
          	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:254)
          	at fcpb.integration.batch.AbstractBatchTestCase.runBare(AbstractBatchTestCase.java:70)
          	at junit.framework.TestResult$1.protect(TestResult.java:106)
          	at junit.framework.TestResult.runProtected(TestResult.java:124)
          	at junit.framework.TestResult.run(TestResult.java:109)
          	at junit.framework.TestCase.run(TestCase.java:118)
          	at junit.framework.TestSuite.runTest(TestSuite.java:208)
          	at junit.framework.TestSuite.run(TestSuite.java:203)
          	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
          	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
          	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
          Caused by: java.io.FileNotFoundException: class path resource [data/fileOutputJob/step.txt] cannot be resolved to URL because it does not exist
          	at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:162)
          	at org.springframework.core.io.ClassPathResource.getFile(ClassPathResource.java:174)
          	at org.springframework.batch.core.resource.StepExecutionResourceProxy.getFile(StepExecutionResourceProxy.java:131)
          	at org.springframework.batch.item.file.FlatFileItemWriter.getOutputState(FlatFileItemWriter.java:232)
          	... 43 more

          Comment


          • #6
            below example worked for me .. I had to add "file:" in order to make it proper url

            <bean id="outputfile" class="org.springframework.batch.core.resource.Ste pExecutionResourceProxy" >
            <property name="filePattern" value="file:c://%JOB_NAME%/%STEP_NAME%" />

            </bean>

            I was using 1.0.1.RELEASE

            Comment

            Working...
            X