The Dark Knight
The Dark Knight

Reputation: 5585

How to resolve Spring Batch Error?

I am trying to learn Spring batch for writing batch jobs in java. So i am using this tutorial.

Now the problem is after I have used all the jars, i started executing the project . This left me with a devious error :

INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e7b1e7b: defining beans [jobLauncher,jobRepository,transactionManager,wordsFWTasklet,numbersFWTasklet,taskletStep,fileWritingJob]; root of factory hierarchy
Sep 3, 2013 8:09:29 AM org.springframework.batch.core.launch.support.CommandLineJobRunner start

SEVERE: Job Terminated in error: Error creating bean with name 'fileWritingJob' defined in class path resource [fileWritingJob.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
Throwable occurred: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileWritingJob' defined in class path resource [fileWritingJob.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)

Caused by: java.lang.NullPointerException
at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:144)
at org.springframework.core.GenericTypeResolver.resolveReturnType(GenericTypeResolver.java:93)

In case, you want to know the code that i have used for my configuration xml, it's below :

fileWritingJob.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="applicationContext.xml"/>

    <bean id="wordsFWTasklet" class="FileCreatorTasklet">
        <property name="filePath" value="C:\\temp\\words.txt"/>
        <property name="content" value="abcdefghijklmnopqrstuwxyz"/>
    </bean>

    <bean id="numbersFWTasklet" class="FileCreatorTasklet">
        <property name="filePath" value="C:\\temp\\numbers.txt"/>
        <property name="content" value="0123456789"/>
    </bean>

    <bean id="taskletStep" abstract="true"
        class="org.springframework.batch.core.step.tasklet.TaskletStep">
        <property name="jobRepository" ref="jobRepository"/>
    </bean>

    <bean id="fileWritingJob" class="org.springframework.batch.core.job.SimpleJob">
        <property name="name" value="fileWritingJob" />
        <property name="steps">
            <list>
                <bean parent="taskletStep">
                    <property name="tasklet" ref="wordsFWTasklet"/>
                    <property name="transactionManager" ref="transactionManager"/>
                </bean>
                <bean parent="taskletStep">
                    <property name="tasklet" ref="numbersFWTasklet"/>
                    <property name="transactionManager" ref="transactionManager"/>
                </bean>
            </list>
        </property>
        <property name="jobRepository" ref="jobRepository"/>
    </bean>

</beans>

EDIT :

ApplicationContext.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <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.SimpleJobRepository">
        <constructor-arg>
            <bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
        </constructor-arg>
        <constructor-arg>
            <bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
        </constructor-arg>
        <constructor-arg>
            <bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
        </constructor-arg>
        <constructor-arg>
            <bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
        </constructor-arg>
    </bean>

    <bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>

</beans>

Can any one tell me what am i doing wrong here ?

Upvotes: 1

Views: 5371

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18383

Which versione of spring-batch are you using? With 2.2.1.RELEASE (and 3.2.3.RELEASE of Spring framework) this example works fine! Libraries (from maven) are:

org.springframework

  • spring-core
  • spring-beans
  • spring-context
  • spring-batch-core
  • spring-batch-infrastructure

Upvotes: 1

Related Questions