1

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 ?

4
  • Can you check whether you have defined beans with name transactionManager in your project Commented Sep 3, 2013 at 12:46
  • @Ashish Yes, i have please see the updated code flow above . Commented Sep 3, 2013 at 12:49
  • I will assume that your class FileCreatorTasklet is on the default package, not not under any other package? Commented Sep 3, 2013 at 13:01
  • @Ashish Yes you are quite right . Commented Sep 3, 2013 at 13:05

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

I am using these jars : commons-logging-1.1.3.jar, spring-2.5.4.jar, spring-batch-core-2.2.1.RELEASE.jar, spring-batch-infrastructure-2.2.1.RELEASE.jar, spring-batch-test-2.2.1.RELEASE.jar. So, i have included all 2.2.1 release versions .
Tried with your config and all works fine. Try upgrade to spring 3.2.3.RELEASE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.