【问题标题】:spring batch ItemProcessorAdapter how to pass multiple argument to targetMethod?spring batch ItemProcessorAdapter如何将多个参数传递给targetMethod?
【发布时间】:2014-04-29 12:10:31
【问题描述】:

下面是我的 ItemProcessor bean,我正在实现 ItemProcessor 接口。它工作正常,但

<beans:bean id="myItemProcessor"
        class="com.st.foundation.MyItemProcessor"
        p:id="#{jobParameters[date]}" p:type="my-type"
        scope="step" />

我想将许多这样的 bean 组合成一个 pojo 并使用 ItemProcessorAdapter。

<beans:bean id="myItemProcessor"
    class="org.springframework.batch.item.adapter.ItemProcessorAdapter"
    p:targetObject-ref="myObject" p:targetMethod="myMethod"
    p:arguments="{jobParameters[date]}"  scope="step" />

但是我的 targetMethod 有多个参数(类型参数和 id)。如何将多个参数传递给适配器,因为它只有 p:arguments 参数?

我尝试用逗号分隔参数,但它不起作用。收到错误“目标类必须声明具有匹配名称和参数类型的方法”。

我也尝试过使用

    <?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:file="http://www.springframework.org/schema/integration/file"
    xmlns:integration="http://www.springframework.org/schema/integration"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <util:list id="myList" value-type="java.lang.String">
        <value>foo</value>
        <value>bar</value>
    </util:list>

来自这个How to define a List bean in Spring?

但我得到“cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素'value'的声明。”

【问题讨论】:

    标签: java spring spring-batch


    【解决方案1】:

    AbstractMethodInvokingDelegator.setArguments() 接受一个 Object 数组作为参数;这个数组的值被用作参数S所以:

    尝试用逗号分隔值

    "p:arguments="{jobParameters[date]},param2,param3"

    或者没有 p 命名空间设施:

    <property name="arguments">
      <list>
        <value>{jobParameters[date]}</value>
        <value>param2</value>
        <value>param3</value>
      </list>
    </property>
    

    【讨论】:

    • 尝试用逗号分隔,但不起作用。收到错误“目标类必须声明具有匹配名称和参数类型的方法”
    • 您在myItemProcessor bean 中的{jobParameters[date]} 之前缺少一个#
    【解决方案2】:

    这对我有用,

    <util:list id="myList" value-type="java.lang.String"
        scope="step">
        <beans:value>value1</beans:value>
        <beans:value>value2</beans:value>
    </util:list>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 2018-06-18
      • 2019-09-27
      • 2016-04-20
      • 2012-04-25
      • 2016-10-28
      • 2014-07-23
      相关资源
      最近更新 更多