2013-01-31 3 views
1

꽤 간단한 설정입니다. 나는 잠재적으로 5m 레코드의 파일을 가지고 있는데,이 파일은 읽고 읽어야 할 일이있다. 그런 다음 db로 보낸다. 가공 및 글쓰기의 메커니즘은 중요하지 않습니다. 경로와 파일 이름 [/opt/etc/app/partner/input_file.csv]을 매개 변수로 프로세스에 전달할 수 있어야합니다. 그렇게하기 쉽고 JobParameters에 추가하여 JobLauncher에 제공하십시오.SpringBatch MultiResourcePartitioner가 jobParameters를 인식하지 못하는 이유는 무엇입니까? 더 중요한 것은 무엇을해야 하는가?

JobParametersBuilder jpBuilder = new JobParametersBuilder() ; 
jpBuilder.addString("filePath", "/opt/etc/app/partner/input_file.csv") ; 
jobLauncher.run(job, jpBuilder.toJobParameters() ; 

이제 문맥을 인식하도록하십시오. 다시 jobParameters를 참조하는 간단한 문제.

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:batch="http://www.springframework.org/schema/batch" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

    <description>PoC to demonstrate variable row content handling</description> 

    <batch:job id="poc" job-repository="jobRepository" incrementer="runIdIncrementer" restartable="true"> 
     <batch:step id="pocReadWriteStep"> 
      <batch:partition step="step" partitioner="partitioner"> 
       <batch:handler task-executor="taskExecutor"/> 
      </batch:partition> 
     </batch:step> 
    </batch:job> 

    <batch:step id="step"> 
     <batch:tasklet task-executor="taskExecutor" throttle-limit="20" transaction-manager="transactionManager" allow-start-if-complete="true"> 
      <batch:transaction-attributes isolation="READ_UNCOMMITTED"/> 
      <batch:chunk 
       reader="reader" 
       processor="processor" 
       writer="writer" 
       commit-interval="20"> 
      </batch:chunk> 
     </batch:tasklet> 
    </batch:step> 

    <bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> 
     <property name="resource" value="file:#{jobParameters['filePath']}"/> 
     <property name="lineMapper"> 
      <bean class="org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper"> 
       <property name="tokenizers"> 
        <map> 
         <entry key="*" value-ref="lineTokenizer"/> 
        </map> 
       </property> 
       <property name="fieldSetMappers"> 
        <map> 
         <entry key="*" value-ref="fieldSetMapper"/> 
        </map> 
       </property> 
      </bean> 
     </property> 
    </bean> 

    <bean id="lineTokenizer" class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"/> 

    <bean id="fieldSetMapper" class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper"/> 

    <bean id="processor" class="com.verifi.springbatchpoc.PocProcessor"/> 

    <bean id="writer" class="com.verifi.springbatchpoc.PocWriter"/> 

    <bean id="runIdIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/> 

    <bean id="partitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner"> 
     <property name="resources" value="file:#{jobParameters['filePath']}"/> 
    </bean> 

    <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> 
     <property name="corePoolSize" value="20"/> 
    </bean> 

</beans> 

MultiResourcePartitioner에서 jobParameters에 대한 참조를 인식하지 못하는 것 외에는 예외입니다. 나는 경로와 파일 이름을 하드 코딩 할 수 있으며 아주 행복하지만이 구현을 위해 메일을 운반하지는 않습니다.

누군가가 물어볼 것이라고 확신하기 때문에 여기에 오류 (물론 그 일부분)의 스택 추적이 있습니다.

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    ... 46 more 
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:207) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:71) 
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52) 
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) 
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:97) 
    at org.springframework.expression.common.CompositeStringExpression.getValue(CompositeStringExpression.java:82) 
    at org.springframework.expression.common.CompositeStringExpression.getValue(CompositeStringExpression.java:1) 
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:138) 
    ... 52 more 

생각, 의견, 제안?

답변

5

난 당신이 범위 = 같은 "단계"를 추가해야한다고 생각 : 그것을 필요로 정확히였습니다

<bean id="partitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner" 
scope="step"> 
     <property name="resources" value="file:#{jobParameters['filePath']}"/> 
    </bean> 
+0

그것은 항상 작은 물건. – JTryon