如何解决Spring Batch Error?

时间:2013-09-03 12:29:54

标签: java spring-batch

我正在尝试学习Spring批处理在java中编写批处理作业。所以我使用这个tutorial

现在问题是在我使用了所有罐子后,我开始执行该项目。这给我留下了一个狡猾的错误:

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)

如果你想知道我用于我的配置xml的代码,它在下面:

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>

编辑:

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>

任何人都可以告诉我这里我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

您使用的是哪个版本的弹簧批?使用 2.2.1.RELEASE (以及 Spring框架 3.2.3.RELEASE ),此示例正常运行! 图书馆(来自maven)是:

<强> org.springframework

  • 弹簧芯
  • 弹簧豆
  • 弹簧上下文
  • 弹簧分批芯
  • 弹簧分批基础设施