我目前正在尝试通过将jobLauncher自动装入控制器来运行Spring Batch进程,这正是问题[here] [1]正在尝试做的问题。但是,我收到一个错误,告诉我我的autowire失败,并且是一个“JobRepository has not been set
”,这是由SimpleJobLauncher上的[afterPropertiesSet()方法] [2]引起的。有谁知道可能导致这种情况的原因?
这是其他提问者的Spring配置,我也在使用:
<job id="writeProductsJob" xmlns="http://www.springframework.org/schema/batch">
<step id="readWrite">
<tasklet task-executor="taskExecutor">
<chunk reader="productItemReader" writer="productItemWriter" commit-interval="10" />
</tasklet>
</step>
</job>
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="5" />
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="taskExecutor" ref="taskExecutor"/>
<property name="transactionManager" ref="transactionManager" />
</bean>
[1]: http://stackoverflow.com/questions/9114162/spring-batch-starting-a-job-from-within-a-spring-mvc-contorller-with-a-new-thre
[2]: http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.batch/spring-batch-core/2.1.0.RELEASE/org/springframework/batch/core/launch/support/SimpleJobLauncher.java#SimpleJobLauncher.afterPropertiesSet%28%29
编辑:这是tranactionManager,jobRepository和jobLauncher的配置:
<?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-3.0.xsd">
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
</beans>