2012-02-03 125 views
0

我正在运行多个作业,并且希望为每个作业都有一个单独的作业存储库(内存中实现)。spring批处理:如何为每个作业设置作业存储库

请在下面找到我尝试过的bean定义。请注意,我试图用范围原型指定bean。

我得到一个java.lang.IllegalArgumentException: JobExecution must already be saved异常。

<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" 
     scope="prototype"> 
    <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> 
+0

任务库中创建一次,所以它并不重要,如果你使用的原型或没有,你能解释一下多一点你是怎么运行的作业? – 2012-02-11 21:58:22

+0

您可能需要创建自己的JobLauncher实现(和其他)来执行此操作。 @Michael Lange在这种情况下是正确的,因为您正在创建单身简单职位启动器,它将创建一个“单一”职位回购。如果您要尝试这样做,您至少需要每个工作的工作启动器。 – 2012-02-26 16:12:47

+0

你为什么试图做每个工作回购? – 2012-02-26 16:13:01

回答

1

这个为我工作,例如,作为一个单元测试jobRepository

<bean id="jobRepository" 
    class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"> 
</bean>