springbatch 给自定义的processor传递JobParameters中设置的参数

1.在配置文件中添加对应的属性值

<bean id="accFeeChannelProcessor" class="com.ninefbank.smallpay.admin.test.AccFeeChannelProcessor" scope="step">
        <property name="loginName" value="#{jobParameters[‘loginName‘]}" />
    </bean>

2.在逻辑类中添加对应的属性以及set方法

package com.ninefbank.smallpay.admin.test;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;

import com.ninefbank.smallpay.admin.feemgr.vo.AccFeeChannel;

/**
 *
 * @author GMM
 *
 */
//@Service("accFeeChannelProcessor")
public class AccFeeChannelProcessor implements ItemProcessor<AccFeeChannel, AccFeeChannel> {
    private static final Logger logger=LoggerFactory.getLogger(AccFeeChannelProcessor.class);
    private String loginName ;
    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }  

    @Override
    public AccFeeChannel process(AccFeeChannel paramI) throws Exception {
        logger.info("springbatch 中读出来的对象为:{}",new Object[]{paramI.toString()});
        paramI.setCreator(loginName);
        paramI.setUpdator(loginName);
        Date date = new Date();
        paramI.setCreateTime(date);
        paramI.setUpdateTime(date);
        logger.info("填充之后的对象信息为:{}",new Object[]{paramI.toString()});
        return paramI;
    }

}

配置文件中的

scope="step"必须得加上 不加上是会报错的:
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘localToDatabaseStep3‘: Cannot resolve reference to bean ‘accFeeChannelProcessor‘ while setting bean property ‘itemProcessor‘; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘accFeeChannelProcessor‘ defined in class path resource [job/job-fee.xml]: 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): Field or property ‘jobParameters‘ cannot be found on object of type ‘org.springframework.beans.factory.config.BeanExpressionContext‘
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1418) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:615) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068) [catalina.jar:7.0.69]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584) [catalina.jar:7.0.69]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [catalina.jar:7.0.69]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572) [catalina.jar:7.0.69]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562) [catalina.jar:7.0.69]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [na:1.7.0_13]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_13]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0_13]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘accFeeChannelProcessor‘ defined in class path resource [job/job-fee.xml]: 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): Field or property ‘jobParameters‘ cannot be found on object of type ‘org.springframework.beans.factory.config.BeanExpressionContext‘
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    ... 25 common frames omitted
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property ‘jobParameters‘ cannot be found on object of type ‘org.springframework.beans.factory.config.BeanExpressionContext‘
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:142) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1315) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:214) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:186) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1418) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    ... 31 common frames omitted
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property ‘jobParameters‘ cannot be found on object of type ‘org.springframework.beans.factory.config.BeanExpressionContext‘
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:216) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:49) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:89) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:139) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    ... 37 common frames omitted
[smallpay-newaccount-admin][2017-07-14 17:31:50 620] INFO  [localhost-startStop-1][org.springframework.web.context.ContextLoader:285]- Root WebApplicationContext: initialization started

百度了一下原来是springbatch的公主病在作祟:这是SpringBatch的一个后绑定技术,就是在生成Step的时候,才去创建bean,因 为这个时候jobparameter才传过来。如果加载配置信息的时候就创建bean,这个时候jobparameter的值还没有产生,会抛出异常。

时间: 2024-10-25 01:15:58

springbatch 给自定义的processor传递JobParameters中设置的参数的相关文章

转:在Eclipse的Debug页签中设置虚拟机参数

http://blog.csdn.net/decorator2015/article/details/50914479 在Eclipse的Debug页签中设置虚拟机参数 步骤 1,Run->Debug configurations->Java Application 2,选中已经写好的项目 3,Arguments->VM arguments 4,在VM arguments 里面就可以对虚拟机的内存参数进行设置 5,设置完成后,Apply->Debug 6,过程结束 截图 写在后面

R语言笔记 R中设置图形参数--函数par()详解

R有着非常强大的绘图功能,我们可以利用简单的几行代码绘制出各种图形来,但是有时候默认的图形设置没法满足我们的需要,甚至会碰到各种各样的小问题:如坐标轴或者标题出界了,或者图例说明的大小或者位置遮挡住了图形,甚至有时候默认的颜色也不能满足我们的需求.如何进行调整呢?这就用到了"强大"的函数par().我们可以通过设定函数par()的各个参数来调整我们的图形,这篇博文就是对函数par()的各个参数进行一下总结. 函数par()的使用格式如下: par(..., no.readonly =

Asp.Net中的获取Web.config中设置的参数!(前后台的代码示例)

一.Web.config中设置代码 <appSettings>         <add key="deleted" value="1"/><!--删除标志-->    </appSettings> 二.在App_Code中建立sys.cs // 注意:需要添加相应的引用命名空间using public class sys{    public static int deleted = int.Parse(Config

ueditor.config.js文件中设置enableAutoSave参数为false就可以关闭本地保存功能。

//启用自动保存 1 ,enableAutoSave: false ueditor1.4.3版本是没有效果的,需要修改代码,在ueditor1.5.0版本已经得到修复. 修改方法 ueditor.all.js文件 找到 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

Android 代码中设置Color参数

今天想绘制一条根据参数颜色动态变化的曲线,参数不固定,因此需要根据参数来获取颜色值.研究了很久,搞了一个通过Paint实现的方案. Paint 中包含了很多方法对其属性进行设置,主要方法如下: setAntiAlias: 设置画笔的锯齿效果. setColor: 设置画笔颜色 setARGB:  设置画笔的a,r,p,g值. setAlpha:  设置Alpha值 setTextSize: 设置字体尺寸. setStyle:  设置画笔风格,空心或者实心. setStrokeWidth: 设置空

从配置文件中取得初始化参数

一般来说,对于一些程序,需要指定其中一些时常会动态变化的参数而不影响程序本身的运行.所以这些时候往往会将这些问题放到配置文件中.从而进行读取和修改就方便很多了.下面是分别配置到servlet中和context中的两种方式: 1.从servlet配置中设置初始化参数,如下: 1)设置参数(servlet的配置): <servlet> <servlet-name>SearchItemServlet</servlet-name> <servlet-class>co

用Handler的post()方法来传递线程中的代码段到主线程中执行

自定义的线程中是不能更新UI的,但是如果遇到更新UI的事情,我们可以用handler的post()方法来将更新UI的方法体,直接传送到主线程中,这样就能直接更新UI了.Handler的post()方法就是将Runnable中的代码段传送到主线程. 布局文件就是个textView,我就不贴了. 全部代码 package com.kale.handler; import android.app.Activity; import android.graphics.Color; import andro

在.Net MVC中自定义ValidationAttribute标签对Model中的属性做验证

写一个继承与ValidationAttribute类的自定义的验证方法 MVC中传递数据时,大多数都会用Model承载数据,并且在传到控制器后,对Model进行一系列的验证. 我平时经常使用的判断方法比Low,因为Model都是不同的,也需要返回很多不同的信息,所以我都是把很多条件语句封装成私有方法,放在控制器的最下边,然后使用的时候直接调用. 下图就是我平时使用的代码格式,我把验证方法都写在了这里,很低级请轻喷. 其实在.Net MVC中,已经提供了很好的验证方法,就是在属性上面加Valida

SpringMVC验证框架Validation自定义注解实现传递参数到国际化资源文件

关于SpringMVC验证框架Validation的使用方法,不是本篇的重点,可参见博文SpringMVC介绍之Validation 在使用Validation时,一定有朋友遇到过一个问题,那就是:无法传递参数到国际化资源文件properties错误描述中. 举个例子: User类中 @NotEmpty(message="{password.empty.error}") private String password; 资源文件validation_zh_CN.properties中为