使用" org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter"重启批处理作业

时间:2014-10-16 22:12:15

标签: java spring spring-batch restart

任何人都可以向我提供有关如何实施" JobNameToJobRestartRequestAdapter"的详细信息。用于通过提供需要执行的作业的名称来重新启动失败作业的类API。

我创建了context-xml文件

    <int:channel id="job-launches" />
    <int:channel id="job-restarts" />

     <int:service-activator id="restartJobClassProperties" input-channel="job-restarts" output-channel="job-requests">
        <bean class="org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter">
            <property name="jobLocator" ref="jobRegistry" />
            <property name="jobExplorer" ref="jobExplorer" />
        </bean>
    </int:service-activator>

    <bean id="jobRegistry" class="org.springframework.batch.core.configuration.JobLocator">
        <property name="name" value="JobNameGoesHere" />
    </bean>

    <bean id="jobExplorer" class="org.springframework.batch.core.explore.JobExplorer" />

在执行正在读取此context.xml文件的主类时,我收到以下错误:

创建名称为

的bean时出错
  

&#39; org.springframework.integration.config.ServiceActivatorFactoryBean#0&#39 ;:   无法创建内部bean   &#39; org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0&#39;   类型   [org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter]   设置bean属性&#39; targetObject&#39 ;;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0&#39;   在类路径资源中定义   [META-INF / spring / restart-job-context.xml]:无法解析引用   bean&#39; jobRegistry&#39;设置bean属性&#39; jobLocator&#39 ;;嵌套   异常是org.springframework.beans.factory.BeanCreationException:   创建名称为&#39; jobRegistry&#39;的bean时出错在类路径中定义   resource [META-INF / spring / restart-job-context.xml]:实例化   豆子失败了;嵌套异常是   org.springframework.beans.BeanInstantiationException:不能   实例化bean类   [org.springframework.batch.core.configuration.JobLocator]:已指定   class是一个接口

我想实现定义批处理作业名称的功能,我想重新启动它,并且可以根据最后执行的步骤从jobexplorer中提取属性。

1 个答案:

答案 0 :(得分:0)

JobLocator是一个界面。您无法定义仅作为接口的bean。我想你想使用JobRegistry。以下是Spring Batch Admin使用的内容:

<bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
    <property name="applicationContextFactories">
        <bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
            <property name="resources" value="classpath*:/META-INF/spring/batch/jobs/*.xml" />
        </bean>
    </property>
    <property name="jobLoader">
        <bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
            <property name="jobRegistry" ref="jobRegistry" />
        </bean>
    </property>
</bean>

<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />

jobRegistry bean是要查找的作业的注册表(它实现了JobLocatorjobLoader向注册表注册作业定义。