Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
第一个spring批处理作业被第二个作业的详细信息覆盖_Spring_Spring Mvc_Quartz Scheduler_Spring Batch - Fatal编程技术网

第一个spring批处理作业被第二个作业的详细信息覆盖

第一个spring批处理作业被第二个作业的详细信息覆盖,spring,spring-mvc,quartz-scheduler,spring-batch,Spring,Spring Mvc,Quartz Scheduler,Spring Batch,我有一个集成了SpringBatch的SpringMVC应用程序。我的spring批处理作业通过cron触发器执行 我在xml中定义了两个批处理作业。第二批作业工作正常,但当我执行第一批作业时,它执行第二批作业 我想我的工作登记不正确。有人能帮我解决什么问题吗 谢谢 第二个作业定义(作业公告栏消息更新.xml) 更多信息。为了尝试了解更多信息,我在org.springframework.batch.core.launch.support.simplejoblancher上放了一个日志 当我在sp

我有一个集成了SpringBatch的SpringMVC应用程序。我的spring批处理作业通过cron触发器执行

我在xml中定义了两个批处理作业。第二批作业工作正常,但当我执行第一批作业时,它执行第二批作业

我想我的工作登记不正确。有人能帮我解决什么问题吗

谢谢

第二个作业定义(作业公告栏消息更新.xml)

更多信息。为了尝试了解更多信息,我在org.springframework.batch.core.launch.support.simplejoblancher上放了一个日志

当我在spring配置中只启用了第一个作业时,日志显示作业每日传输计数大约需要2.5分钟来执行

[INFO] 2014-03-19 07:15:00,187 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] launched with the following parameters: [{run date=1395173700052}]
[INFO] 2014-03-19 07:17:43,934 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] completed with the following parameters: [{run date=1395173700052}] and the following status: [COMPLETED]
当我在spring配置中只启用了这两个作业时,日志显示作业每日传输计数大约只需要8毫秒,而这应该需要更长的时间。i、 它什么也没做

[INFO] 2014-04-15 07:15:00,225 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] launched with the following parameters: [{run date=1397510100128}]
[INFO] 2014-04-15 07:15:08,977 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] completed with the following parameters: [{run date=1397510100128}] and the following status: [COMPLETED]
[INFO] 2014-04-15 07:30:00,009 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-bulletin-bar-msg-update]] launched with the following parameters: [{run date=1397511000007}]
[INFO] 2014-04-15 07:30:05,217 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-bulletin-bar-msg-update]] completed with the following parameters: [{run date=1397511000007}] and the following status: [COMPLETED]

我也有类似的问题。对我有效的是重命名步骤ID,使其唯一。值得一试

我遇到了一个类似的问题,这是spring batch版本4.2.1.RELEASE,使用spring boot版本2.1.10运行。RELEASE由spring framework版本5.1.11.RELEASE提供动力。因此,这里(可能)有一个例子,说明当框架“对同时代人的约克不平等”时会发生什么。另一个需要考虑的是作业仓库的持久性,这意味着在某个时候,这个工作会被错误地调用。这需要很多调试断点,尤其是在作业启动程序周围。所以我所做的就是随意更改步骤的名称。在我的假设中,这将迫使框架检测步骤ID中的更改,并刷新数据库中的定义。成功了。如果我坚持使用spring boot版本的spring batch,仍然要找出步骤id名称调用问题是否可以自行解决。

我也有同样的问题,必须重命名所有步骤

读到某处 @EnableBatchProcessing(模块化=真)


它可能会将作业保持在单独的“上下文”中

您能给我们展示一下
com.myer.reporting.batch.JobLauncherDetails
吗?谢谢您的帮助。我已经在文章的底部添加了这个类。一切看起来都很干净。复制你的配置,我制作了一个简单的示例,它只记录了作业名称,并且正确地输出了两个作业,即使我让它运行一个只有1个线程的池,也会循环它们。您还可以发布批处理属性或cron表达式吗?您是如何发现它只执行了第二个作业的?我之所以说它只执行第二个作业,是因为我在第一个作业和第二个作业中的JDBCItemReader上有断点。当我在xml配置中只配置了第一个作业时,断点会在第一个作业的jdbcItemReader中着陆,但当我在xml配置中配置了两个作业时,断点会在第二个jdbcItemReader中着陆,即使它似乎从作业注册表中拾取了正确的作业。我已将日志放在org.springframework.batch.core.launch.support上。从quartz和spring批处理的角度来看,将添加outputWell,似乎调度和作业启动工作正常。您的意思是说,如果在第二个jdbc项读取器中禁用断点,调试器将不会暂停并跳转到第一个jdbc项读取器中的断点?这并没有提供问题的答案。若要评论或要求作者澄清,请在他们的帖子下方留下评论-你可以随时对自己的帖子发表评论,一旦你有足够的评论,你就可以发表评论。我提供了一个可能的解决方案。解决方法是为步骤ID指定唯一的名称。@jww-请不要因为不真实的原因而标记答案,尤其是懒散地使用不适用的表单文本。这是一个非常好的答案。谢谢克里斯。答案已在系统中标记。另外,“值得一试”让它看起来像是猜测,更适合作为评论而不是回答。非常感谢athreya86!!这值得一试,而且成功了!真不敢相信。你是一个传奇。这是spring批处理错误吗?
<beans profile="pre,prod">
    <!-- jobs -->
    <import resource="./jobs/job-daily-tran-counts.xml" />
    <import resource="./jobs/job-bulletin-bar-msg-update.xml" />    

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobDetails">
           <list>
              <ref bean="dailyTranCountJobDetail" />
              <ref bean="bulletinBarMsgUpdateJobDetail" />
           </list>
        </property>
        <property name="triggers">
           <list>
              <ref bean="dailyTranCountCronTrigger" />
              <ref bean="bulletinBarMsgUpdateCronTrigger" />
           </list>
        </property>
    </bean>

    <!-- scheduling properties -->
    <util:properties id="batchProps" location="classpath:batch.properties" />
    <context:property-placeholder properties-ref="batchProps" />        

    <!-- triggers -->
    <bean id="dailyTranCountCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="dailyTranCountJobDetail" />
        <property name="cronExpression" value="#{batchProps['cron.dailyTranCounts']}" />
    </bean>


    <bean id="bulletinBarMsgUpdateCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="bulletinBarMsgUpdateJobDetail" />
        <property name="cronExpression" value="#{batchProps['cron.bulletinBarUpdateMsg']}" />
    </bean>     



    <!-- job detail -->
    <bean id="dailyTranCountJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="job-daily-tran-counts" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
            </map>
        </property>
    </bean> 

    <bean id="bulletinBarMsgUpdateJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
        <property name="group" value="quartz-batch" />
        <property name="jobDataAsMap">
            <map>
                <entry key="jobName" value="job-bulletin-bar-msg-update" />
                <entry key="jobLocator" value-ref="jobRegistry" />
                <entry key="jobLauncher" value-ref="jobLauncher" />
            </map>
        </property>
    </bean>

</beans>            
public class JobLauncherDetails extends QuartzJobBean {

    static final String JOB_NAME = "jobName";

    private JobLocator jobLocator;

    private JobLauncher jobLauncher;

    public void setJobLocator(JobLocator jobLocator) {
        this.jobLocator = jobLocator;
    }

    public void setJobLauncher(JobLauncher jobLauncher) {
        this.jobLauncher = jobLauncher;
    }

    @SuppressWarnings("unchecked")
    protected void executeInternal(JobExecutionContext context) {

        Map<String, Object> jobDataMap = context.getMergedJobDataMap();

        String jobName = (String) jobDataMap.get(JOB_NAME);

        JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap);

        try {
            jobLauncher.run(jobLocator.getJob(jobName), jobParameters);
        } catch (JobExecutionException e) {
            e.printStackTrace();
        }
    }

    //get params from jobDataAsMap property, job-quartz.xml
    private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap) {

        JobParametersBuilder builder = new JobParametersBuilder();

        for (Entry<String, Object> entry : jobDataMap.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (value instanceof String && !key.equals(JOB_NAME)) {
                builder.addString(key, (String) value);
            } else if (value instanceof Float || value instanceof Double) {
                builder.addDouble(key, ((Number) value).doubleValue());
            } else if (value instanceof Integer || value instanceof Long) {
                builder.addLong(key, ((Number) value).longValue());
            } else if (value instanceof Date) {
                builder.addDate(key, (Date) value);
            } else {
                // JobDataMap contains values which are not job parameters
                // (ignoring)
            }
        }

        //need unique job parameter to rerun the same job
        builder.addDate("run date", new Date());

        return builder.toJobParameters();

    }

}
#http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
cron.dailyTranCounts=0 15 07 * * ? *
cron.bulletinBarUpdateMsg=0 30 07 * * ? *
[INFO] 2014-03-19 07:15:00,187 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] launched with the following parameters: [{run date=1395173700052}]
[INFO] 2014-03-19 07:17:43,934 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] completed with the following parameters: [{run date=1395173700052}] and the following status: [COMPLETED]
[INFO] 2014-04-15 07:15:00,225 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] launched with the following parameters: [{run date=1397510100128}]
[INFO] 2014-04-15 07:15:08,977 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] completed with the following parameters: [{run date=1397510100128}] and the following status: [COMPLETED]
[INFO] 2014-04-15 07:30:00,009 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-bulletin-bar-msg-update]] launched with the following parameters: [{run date=1397511000007}]
[INFO] 2014-04-15 07:30:05,217 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-bulletin-bar-msg-update]] completed with the following parameters: [{run date=1397511000007}] and the following status: [COMPLETED]