Spring 动态提供输入、输出路径时出错

Spring 动态提供输入、输出路径时出错,spring,spring-batch,Spring,Spring Batch,我创建了一个多文件读取器和平面文件写入器(稍后,我必须将其扩展为多文件读取到多文件写入,一对一映射)。当我通过属性文件提供输入路径时,一切正常,但当我尝试通过jobExecutionContext提供路径时,它开始给我错误。令我惊讶的是,作者成功地从executionContext中选择了路径,并编写了我提供的任何位置,但没有编写读者 PS:我使用的是“SingleItemPeakableItemReader”,因为我文件中的数据是多行记录,无法确定一条记录何时结束。知道记录2已开始的唯一方法是

我创建了一个多文件读取器和平面文件写入器(稍后,我必须将其扩展为多文件读取到多文件写入,一对一映射)。当我通过属性文件提供输入路径时,一切正常,但当我尝试通过jobExecutionContext提供路径时,它开始给我错误。令我惊讶的是,作者成功地从executionContext中选择了路径,并编写了我提供的任何位置,但没有编写读者

PS:我使用的是“SingleItemPeakableItemReader”,因为我文件中的数据是多行记录,无法确定一条记录何时结束。知道记录2已开始的唯一方法是当您有权访问下一行并且您知道它是新记录的开始时

有人能透过一些光线,知道我做错了什么

<bean id="itemReader" class="com.varun.reader.AccountDataReader">
    <property name="fieldSetReader"         ref="PeekableitemReader" />
    <property name="headerFieldSetMapper"   ref="headerFieldSetMapper" />
    <property name="multiReader"            ref="multiResourceReader"/>
</bean>

<bean id="PeekableitemReader" class="org.springframework.batch.item.support.SingleItemPeekableItemReader" >
    <property name="delegate" ref="multiResourceReader"/>
</bean>

<bean id="multiResourceReader"  class=" org.springframework.batch.item.file.MultiResourceItemReader" >
    <property name="resources" value="file:${file.input.dir}*.DAT" />
    <property name="delegate" ref="fileItemReader" />
</bean>

<bean id="fileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer" ref="accountDataTokenizer"/>
            <property name="fieldSetMapper">
                <bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" />
            </property>
        </bean>
    </property>
    <property name="comments" value=""></property>
</bean>

当我在multiresourceReader中提供以下资源时,它会出错

<property name="resources" value="file:#{JobExecutionContext[input_dir]}*.DAT" />

错误日志如下所示:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'itemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemReader' defined in class path resource [spring/config/process-config.xml]: Cannot resolve reference to bean 'PeekableitemReader' while setting bean property 'fieldSetReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PeekableitemReader' defined in class path resource [spring/config/process-config.xml]: Cannot resolve reference to bean 'multiResourceReader' while setting bean property 'delegate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiResourceReader' defined in class path resource [spring/config/process-config.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): Property or field 'JobExecutionContext' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
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)
线程“main”org.springframework.beans.factory.BeanCreationException中的异常:创建名为“step1”的bean时出错:设置bean属性“itemReader”时无法解析对bean“itemReader”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“itemReader”的bean时出错,该bean在类路径资源[spring/config/process config.xml]中定义:在设置bean属性“fieldSetReader”时无法解析对bean“PeakableItemReader”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“PeakableItemReader”(在类路径资源[spring/config/process config.xml]中定义)的bean时出错:设置bean属性“delegate”时无法解析对bean“multiResourceReader”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“multiResourceReader”的bean时出错,该bean在类路径资源[spring/config/process config.xml]中定义:初始化bean失败;嵌套异常为org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常为org.springframework.expression.spel.SpelEvaluationException:EL1008E:(位置0):在类型为“org.springframework.beans.factory.config.BeanExpressionContext”的对象上找不到属性或字段“JobExecutionContext”-可能不是公共的? 位于org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) 在org.springframework.beans.factory.support.BeanDefinitionValueResolver.ResolveValueIfNeeded上(BeanDefinitionValueResolver.java:108) 位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481) 位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) 位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 位于org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:753) 位于org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) 位于org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 位于org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:139) 位于org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:83) 在将多读取器作用域作为步骤后,我得到如下错误。我也尝试将作用域放在所有其他委托读取器上,但我得到了相同的错误

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'itemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemReader' defined in class path resource [spring/config/process-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy11 implementing org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.item.file.MultiResourceItemReader] for property 'multiReader'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy11 implementing org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.item.file.MultiResourceItemReader] for property 'multiReader': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
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.varun.JobScheduler.main(JobScheduler.java:9)
线程“main”org.springframework.beans.factory.BeanCreationException中的异常:创建名为“step1”的bean时出错:设置bean属性“itemReader”时无法解析对bean“itemReader”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“itemReader”的bean时出错,该bean在类路径资源[spring/config/process config.xml]中定义:初始化bean失败;嵌套异常为org.springframework.beans.ConversionNotSupportedException:未能转换类型的属性值[com.sun.proxy.$Proxy11实现org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.framework.adised]到所需类型属性“multiReader”的[org.springframework.batch.item.file.MultiResourceItemReader];嵌套异常为java.lang.IllegalStateException:无法转换类型的值[com.sun.proxy.$Proxy11实现org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.framework.adised]到所需类型[org.springframework.batch.i]
public class AccountDataReader implements ItemReader<AccountDataBO> {
private static Log log = LogFactory.getLog(AccountDataReader.class);
private boolean recordFinished;

private AccountDataBO acctObj = new AccountDataBO();

private SingleItemPeekableItemReader<FieldSet> fieldSetReader;
private HeaderFieldSetMapper headerFieldSetMapper;
private MultiResourceItemReader<FieldSet> multiReader;

@Override
public AccountDataBO read() throws Exception {
    recordFinished = false;

    while (!recordFinished) {
        process(fieldSetReader.read());
    }
    AccountDataBO result = acctObj;
    acctObj = new AccountDataBO();

    return result;
}

private void process(FieldSet fieldSet) throws Exception {

    if (fieldSet == null) {
        log.debug("FINISHED Reading");
        recordFinished = true;
        acctObj=null;
        return;
    }

    String lineId = fieldSet.readString(0);

    if (!StringUtils.isEmpty(lineId) && lineId.contains(AccountDataBO.ACCOUNT)) {
        log.debug("Starting new Record");
        acctObj.setHeader(headerFieldSetMapper.mapFieldSet(fieldSet));
        acctObj.setResource(multiReader.getCurrentResource());

    }

    //Code

}

private void CheckEOFNewAccount() throws Exception {
    if ((fieldSetReader.peek() != null
            && ((fieldSetReader.peek().getValues())[0].contains(AccountDataBO.ACCOUNT)))
            || fieldSetReader.peek() == null) {
        log.debug("Next Line is Account or EOF Hence returning for current Account");
        recordFinished = true;
        return;
    }
}

public void setFieldSetReader(SingleItemPeekableItemReader<FieldSet> fieldSetReader) {
    this.fieldSetReader = fieldSetReader;
}

public void setHeaderFieldSetMapper(HeaderFieldSetMapper headerFieldSetMapper) {
    this.headerFieldSetMapper = headerFieldSetMapper;
}

public void setMultiReader(MultiResourceItemReader<FieldSet> multiReader) {
    this.multiReader = multiReader;
}
<bean id="multiResourceReader"  
      class=" org.springframework.batch.item.file.MultiResourceItemReader" >
<bean id="multiResourceReader"  
      class=" org.springframework.batch.item.file.MultiResourceItemReader" 
      scope="step" >