我正在尝试学习 Spring 批处理以在 java 中编写批处理作业。所以我正在使用本教程。
现在的问题是在我用完所有的 jar 之后,我开始执行项目。这给我留下了一个狡猾的错误:
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 的代码,如下所示:
文件写作工作.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>
编辑 :
应用程序上下文.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>
谁能告诉我我在这里做错了什么?