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

任何人都可以通过提供需要执行的作业的名称来向我提供有关如何实现“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':无法创建[org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter]类型的内部'org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0'设置bean属性'targetObject';嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[META-INF / spring / restart-job-context中定义的名称'org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0'创建bean时出错.xml]:设置bean属性'jobLocator'时无法解析对'jobRegistry'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[META-INF / spring / restart-job-context.xml]中定义名称为'jobRegistry'的bean时出错:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.batch.core.configuration.JobLocator]:指定的类是一个接口

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

回答(1)

2 years ago

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是要从中查找的作业的注册表(它确实实现 JobLocator . jobLoader 使用注册表注册作业定义 .