小编JTr*_*yon的帖子

为什么SpringBatch MultiResourcePartitioner无法识别jobParameters?更重要的是,该怎么办呢?

这是一个非常简单的设置.我有一个潜在的5m记录的文件,我需要阅读并做一些工作,然后发送到数据库.处理和写作的机制并不重要.我需要能够将路径和文件名[/opt/etc/app/partner/input_file.csv]作为参数传递给进程.这很容易,将它添加到JobParameters并将其提供给JobLauncher.

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

完成,现在让上下文意识到它.再次简单的引用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 …
Run Code Online (Sandbox Code Playgroud)

java batch-processing spring-batch applicationcontext

1
推荐指数
1
解决办法
3051
查看次数