gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:03:58 25 4
gpt4 key购买 nike

下面是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com