Results 1 to 3 of 3

Thread: Batch is unable to write to files

  1. #1
    Join Date
    Oct 2012
    Posts
    11

    Default Batch is unable to write to files

    Hello,
    So I have been working with the Sample Batch project provided by STS using Spring Batch 2.1.7 along with Spring Web Admin 1.2.0 and I was able to create several jobs that cover reading/writing delimited flat files, xml files, and database. Everything is working fine. Now I am configuring Spring Batch Web Admin as a completely seperate project and I imported the jobs I created in my other Spring Batch project to this one. I am able to successfully run the database jobs fine, but any jobs that work with writing files are not working as expected. For both flatfile and xml jobs, I read from a flatfile/xml file and write to another flatfile/xml file. When I execute the job via batch web admin, the web admin says that the job executed successfully and says that the appropriate number of reads and writes are successful. The problem is when I check the classpath to look for these written files, they are NOT THERE! In the other Batch project, it works fine. In this batch web admin project, the files are not getting written to classpath/src/main/resources. Below is a sample of the XML job. Any help is greatly appreciated. Thanks!

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:batch="http://www.springframework.org/schema/batch"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
    	<description>Example job to get you started. It provides a skeleton for a typical batch application.</description>
     	
    	<batch:job id="xmlProductProcessing" incrementer="sampleIncrementer">
    		<batch:step id="productXMLProcessingChunk"  >			
    			<batch:tasklet transaction-manager="transactionManager" start-limit="100" >
    				<batch:chunk reader="productXMLReader"
    							 processor="productProcessor"
    							 writer="productXMLWriter"
    							 commit-interval="10" />
    			</batch:tasklet>
    		</batch:step>
    	</batch:job>
    	
    	<bean id="productXMLReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
    		<property name="resource" value="products.xml" />
    		<property name="fragmentRootElementName" value="product" />
    		<property name="unmarshaller" ref="productXMLUnmarshaller" />
    	</bean>
    
    	<bean id="productXMLUnmarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
    		<property name="mappingLocation" value="mapping.xml" />
    	</bean>
    	
    	<bean id="productXMLWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
    		<property name="resource" value="file:src/main/resources/productsWrite.xml" />
    		<property name="overwriteOutput" value="true" />
    		<property name="rootTagName" value="products" />
    		<property name="marshaller" ref="productXMLMarshaller" />
    	</bean>
    	
    	<bean id="productXMLMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
    		<property name="mappingLocation" value="mapping.xml" />
    	</bean>
    </beans>
    Last edited by bravaldi; Jan 11th, 2013 at 05:59 PM. Reason: Added version for Batch Web Admin

  2. #2
    Join Date
    Oct 2012
    Posts
    11

    Default

    This problem is probably related to the fact that I am executing batch within a web container as opposed to executing the commandlinerunner as I was doing previously right? I tried pointing the resource to file:/tmp/productsWrite.xml" and it was not able to write it there either. I am using Tomcat 7. Any help would be greatly appreciated. Thanks!
    Last edited by bravaldi; Jan 11th, 2013 at 05:57 PM.

  3. #3
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    I wouldn't expect you to be able to write to a classpath location within a container. That being said, is Tomcat running under a user's name that has permissions to write to the directories you are trying to write to? Also, what is the exception being thrown when the ItemWriter tries to open the file?
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Tags for this Thread

Posting Permissions

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