在Spring批处理中如何从jobParameters设置throttle-limit

时间:2015-07-09 16:58:47

标签: spring spring-batch batch-processing

我正在尝试将限制作为jobParameter传递。在开始批处理作业之前,我需要根据需要处理的记录数来设置线程和页面大小。

我正在使用下面的配置。它给出错误。 `

<batch:step id="step2" next="step3">
            <batch:tasklet transaction-manager="transactionManager"
                task-executor="taskExecutor" throttle-limit="#{jobParameters['threadNumber']}">

                <batch:chunk reader="pagingItemReader" writer="databaseItemWriter"
                    processor="itemProcessor" commit-interval="#{jobParameters['chunkSize']}" /> 

            </batch:tasklet>
        </batch:step>`

获得以下错误 `

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step2': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.wdpr.payment.batch.BatchApp.main(BatchApp.java:37)

1 个答案:

答案 0 :(得分:0)

使用架构配置无法正常工作,因为它不允许您将ChunkOrientedTasklet设置为步骤作用域。您必须手动配置该步骤才能执行您尝试的操作。

您最好在taskExecutor中管理限制限制(使该步骤成为范围)。