java - spring batch ItemProcessorAdapter如何将多个参数传递给targetMethod?

标签 java spring spring-batch

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

<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:匹配通配符严格,但找不到元素“值”的声明。”

最佳答案

AbstractMethodInvokingDelegator.setArguments()接受对象数组作为参数;该数组的值用作参数,因此:

尝试用逗号分隔值

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

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

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

关于java - spring batch ItemProcessorAdapter如何将多个参数传递给targetMethod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23364288/

相关文章:

java - 如何从 Spring Initializer 解压生成的项目?

spring - 如何防止null RequestParam引发异常?

java - Spring Web 服务客户端和服务器 - 未找到端点映射

java - Spring批MySql序列 "Could not obtain last_insert_id()"重新保护引擎类型

java - 在后台录制音频时出现问题

java - 为什么我的 libGDX 小程序会产生此 SecurityException?

java.sql.SQLException : Io exception: Got minus one from a read call during JDBC connection with oracle 11g

java - Thread.sleep() 有时不工作

java - @ManyToOne 不会将父键列保留在子表中

jakarta-ee - Spring Batch 无资源 JobRepository