Announcement Announcement Module
Collapse
No announcement yet.
Reading from XML File having Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading from XML File having Error

    HI,
    I am trying the run the xmlStaxJob job which read from XML file but i am getting an error
    SEVERE: Job Terminated in error:
    java.lang.NullPointerException
    at org.springframework.batch.core.launch.support.Comm andLineJobRunner.start(CommandLineJobRunner.java:2 05) at org.springframework.batch.core.launch.support.Comm andLineJobRunner.ma
    in(CommandLineJobRunner.java:252)Mar 5, 2009 10:58:30 AM org.springframework.context.support.AbstractApplic ationC
    ontext doClose

    Please let me know if i am doing something wrong.
    XML File
    ?xml version="1.0" encoding="UTF-8"?>
    <records>
    <trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
    <isin>XYZ0001</isin>
    <quantity>5</quantity>
    <price>11.39</price>
    <customer>Customer1</customer>
    </trade>
    <trade xmlns="http://springframework.org/batch/sample/io/oxm/domain">
    <isin>XYZ0002</isin>
    <quantity>2</quantity>
    <price>72.99</price>
    <customer>Customer2c</customer>
    </trade>
    </records>
    Here is my Job.


    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns="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/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    <description>
    Batch Byte Process
    </description>

    <import resource="data-source-context.xml" />

    <bean id="jobRepository"
    class="org.springframework.batch.core.repository.s upport.JobRepositoryFactoryBean">
    <property name="databaseType" value="mysql" />
    <property name="dataSource" ref="dataSourceMYSQL" />
    <property name="transactionManager" ref="transactionManager" />
    </bean>
    <bean id="simpleStep" class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean"
    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="mapJobRepository" class="org.springframework.batch.core.repository.s upport.MapJobRepositoryFactoryBean" >
    <property name="transactionManager" ref="transactionManager"/>
    </bean>
    <bean id="xmlByteProcessJob" class="org.springframework.batch.core.job.SimpleJo b">
    <property name="steps">
    <bean id="step1" parent="simpleStep">
    <property name="itemReader">
    <bean
    class="org.springframework.batch.item.xml.StaxEven tItemReader">
    <property name="fragmentRootElementName"
    value="trade" />
    <property name="resource"
    value="file:C:\xmlInput\20070918.testStream.xmlFil eStep.xml" />
    <property name="fragmentDeserializer">
    <bean
    class="org.springframework.batch.item.xml.oxm.Unma rshallingEventReaderDeserializer">
    <constructor-arg>
    <bean
    class="org.springframework.oxm.xstream.XStreamMars haller">
    <property name="aliases"
    ref="aliases" />
    </bean>
    </constructor-arg>
    </bean>
    </property>
    </bean>
    </property>
    <property name="itemWriter" ref="tradeStaxWriter" />
    </bean>
    </property>
    <property name="jobRepository" ref="jobRepository" />
    <property name="restartable" value="true" />
    </bean>

    <bean class="org.springframework.batch.item.xml.StaxEven tItemWriter"
    id="tradeStaxWriter">
    <property name="resource"
    value="file:C:\xmlInput\20070918.testStream.xmlFil eStep.output.xml" />
    <property name="serializer" ref="tradeMarshallingSerializer" />
    <property name="rootTagName" value="trades" />
    <property name="overwriteOutput" value="true" />
    </bean>

    <bean
    class="org.springframework.batch.item.xml.oxm.Mars hallingEventWriterSerializer"
    id="tradeMarshallingSerializer">
    <constructor-arg>
    <bean
    class="org.springframework.oxm.xstream.XStreamMars haller">
    <property name="aliases" ref="aliases" />
    </bean>
    </constructor-arg>
    </bean>

    <util:map id="aliases">
    <entry key="trade"
    value="us.tn.state.trust.batch.byteProcess.domain. Trade" />
    <entry key="isin" value="java.lang.String" />
    <entry key="quantity" value="long" />
    <entry key="price" value="java.math.BigDecimal" />
    <entry key="customer" value="java.lang.String" />
    </util:map>
    <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.Cu stomEditorConfigurer">
    <property name="customEditors">
    <map>
    <entry key="int[]">
    <bean class="org.springframework.batch.support.IntArrayP ropertyEditor" />
    </entry>
    <entry key="org.springframework.batch.item.file.transform .Range[]">
    <bean class="org.springframework.batch.item.file.transfo rm.RangeArrayPropertyEditor" />
    </entry>
    <entry key="java.util.Date">
    <bean class="org.springframework.beans.propertyeditors.C ustomDateEditor">
    <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.Pro cessorLogAdvice" />

    <bean id="eventAdvice" class="org.springframework.batch.sample.advice.Ste pExecutionApplicationEventAdvice" />
    </beans>


    Pls. help..........

  • #2
    That is definitely not enough information to help with an issue, it may even be completely unrelated to the XML reading. I think you need to change your log levels to try and get a more detailed error. Also, please use code tags when posting stack traces or code snippets.

    Comment


    • #3
      Can you please check my xml file reading
      Code:
      <bean id="xmlByteProcessJob" class="org.springframework.batch.core.job.SimpleJob">
      		<property name="steps">
      			<bean id="step1" parent="simpleStep">
      				<property name="itemReader">
      					<bean
      						class="org.springframework.batch.item.xml.StaxEventItemReader">
      						<property name="fragmentRootElementName"
      							value="records" />
      						<property name="resource"
      							value="file:C:/xmlInput/20070918.testStream.xmlFileStep.xml" />
      						<property name="fragmentDeserializer">
      							<bean
      								class="org.springframework.batch.item.xml.oxm.UnmarshallingEventReaderDeserializer">
      								<constructor-arg>
      									<bean
      										class="org.springframework.oxm.xstream.XStreamMarshaller">
      										<property name="aliases"
      											ref="aliases" />
      									</bean>
      								</constructor-arg>
      							</bean>
      						</property>
      					</bean>
      				</property>
      				<property name="itemWriter" ref="tradeStaxWriter" />
      			</bean>
      		</property>
      		<property name="jobRepository" ref="jobRepository" />
      		<property name="restartable" value="true" />
      	</bean>
      <util:map id="aliases">
      		<entry key="trade"
      			value="SpringBatchTest.domain.Trade" />
      		<entry key="isin" value="java.lang.String" />
      		<entry key="quantity" value="long" />
      		<entry key="price" value="java.math.BigDecimal" />
      		<entry key="customer" value="java.lang.String" />
      	</util:map>
      my XML File is
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <records>
        <trade>
          <isin>XYZ0001</isin>
          <quantity>5</quantity>
          <price>11.39</price>
          <customer>Customer1</customer>
        </trade>
      </record>
      and i have written my domain class which is
      Code:
      public class Trade implements Serializable {
          private String isin = "";
          private long quantity = 0;
          private BigDecimal price = new BigDecimal(0);
          private String customer = "";
      
          public Trade() {
          }
          
          public Trade(String isin, long quantity, BigDecimal price, String customer){
          	this.isin = isin;
          	this.quantity = quantity;
          	this.price = price;
          	this.customer = customer;
          }
      
          public void setCustomer(String customer) {
      		this.customer = customer;
      	}
      
      	public void setIsin(String isin) {
      		this.isin = isin;
      	}
      
      	public void setPrice(BigDecimal price) {
      		this.price = price;
      	}
      
      	public void setQuantity(long quantity) {
      		this.quantity = quantity;
      	}
      
      	public String getIsin() {
              return isin;
          }
      
          public BigDecimal getPrice() {
              return price;
          }
      
          public long getQuantity() {
              return quantity;
          }
      
          public String getCustomer() {
              return customer;
          }
      
          public String toString() {
              return "Trade: [isin=" + this.isin + ",quantity=" + this.quantity + ",price="
                  + this.price + ",customer=" + this.customer + "]";
          }
          
          public boolean equals(Object o) {
      		return EqualsBuilder.reflectionEquals(this, o);
      	}
      
      	public int hashCode() {
      		return HashCodeBuilder.reflectionHashCode(this);
      	}
      }
      Please let me know if i am doing anything wrong. Your input is very important to me. Thanks a lot
      Last edited by adish1234; Mar 5th, 2009, 03:30 PM.

      Comment


      • #4
        It would really help if you could provide a stack trace as well.

        Comment


        • #5
          Originally posted by lucasward View Post
          It would really help if you could provide a stack trace as well.
          This is my Stack Trace

          Code:
          C:\workSpaces\Batch-ByteProcess>java -jar target\Batch-ByteProcess-1.0.jar ByteProcessJob.xml xmlByteProcessJob schedule.run=86
          Mar 5, 2009 3:32:06 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
          INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@e5b723: display name [org.springframework.context.support.ClassPathXmlApplic
          ationContext@e5b723]; startup date [Thu Mar 05 15:32:06 CST 2009]; root of context hierarchy
          Mar 5, 2009 3:32:06 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
          INFO: Loading XML bean definitions from class path resource [ByteProcessJob.xml]
          Mar 5, 2009 3:32:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
          INFO: Loading XML bean definitions from class path resource [data-source-context.xml]
          Mar 5, 2009 3:32:07 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
          INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@e5b723]: org.springframework.beans.factory.suppor
          t.DefaultListableBeanFactory@1f06dc3
          Mar 5, 2009 3:32:07 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
          INFO: Loading properties file from class path resource [jdbc.properties]
          Mar 5, 2009 3:32:07 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
          INFO: Loading properties file from class path resource [mysql.properties]
          Mar 5, 2009 3:32:07 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
          INFO: Loading properties file from class path resource [system.properties]
          Mar 5, 2009 3:32:08 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
          INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1f06dc3: defining beans [propertyConfigurer,dataSourc
          eMYSQL,dataSourceDB2,transactionManager,jdbcTemplate,jobRepository,simpleStep,mapJobRepository,xmlByteProcessJob,tradeStaxWriter,tradeMarshallingSerializer,alia
          ses,customEditorConfigurer,logAdvice,eventAdvice]; root of factory hierarchy 
          Mar 5, 2009 3:32:08 PM org.springframework.batch.core.launch.support.CommandLine
          JobRunner start
          SEVERE: Job Terminated in error:
          java.lang.NullPointerException
                  at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:205)
                  at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:252)
          Mar 5, 2009 3:32:09 PM org.springframework.context.support.AbstractApplicationContext doClose
          INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@e5b723: display name [org.springframework.context.support.ClassPathXmlApplicati
          onContext@e5b723]; startup date [Thu Mar 05 15:32:06 CST 2009]; root of contexthierarchy
          Mar 5, 2009 3:32:09 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
          INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1f06dc3: defining beans [propertyConfigurer,dataSourceMYSQL,
          dataSourceDB2,transactionManager,jdbcTemplate,jobRepository,simpleStep,mapJobRepository,xmlByteProcessJob,tradeStaxWriter,tradeMarshallingSerializer,aliases,cus
          tomEditorConfigurer,logAdvice,eventAdvice]; root of factory hierarchy
          Thanks a lot for your help

          Comment


          • #6
            Looks like there's no JobLauncher in your application context.

            Comment


            • #7
              Originally posted by Dave Syer View Post
              Looks like there's no JobLauncher in your application context.
              Hi Dave,
              Thanks a lot . I mistakely missed the JobLauncher. Thanks again.

              can you please tell me if i want to update the element value into a table using ItemWriter then what i need to do???

              I really thanks to you for your help...

              Comment

              Working...
              X