【问题标题】:Using "org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter" restart Batch Job使用“org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter”重启批处理作业
【发布时间】:2014-12-12 10:22:20
【问题描述】:

谁能提供详细信息,如如何通过提供需要执行的作业名称来实现“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 时出错

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

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

【问题讨论】:

    标签: java spring spring-batch restart


    【解决方案1】:

    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 向注册表注册作业定义。

    【讨论】:

    • 感谢您提供详细信息,我仍然不明白如何传递需要从最后失败的步骤重新启动的作业名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 2019-11-16
    相关资源
    最近更新 更多