将 2/n 个(多个)参数传递给“int-jdbc:stored-proc-outbound-gateway" [英] Passing 2/n-number of (multiple) parameters to 'int-jdbc:stored-proc-outbound-gateway'
问题描述
大家好,我需要帮助:)
Hi guys i need help here :)
以前当我试图只传递一个变量时,它工作正常.现在,只要我尝试使用 Spring Integration 传递 2/n 个参数,就会出现以下有效负载"异常,我不清楚.
Previously when I tried to pass only one variable, it was working fine. Now as soon as I am trying to pass 2/n-number of parameters by using Spring Integration, getting following 'payload' exceptions, which I am not clear about.
我得到的异常如下:
[2014-10-31 12:12:43,943][WARN ]GatewayProxyFactoryBean$MethodInvocationGateway.doSendAndReceive: failure occurred in gateway sendAndReceive
org.springframework.messaging.converter.MessageConversionException: failed to convert object to Message
at org.springframework.integration.support.converter.SimpleMessageConverter.toMessage(SimpleMessageConverter.java:85)
at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:112)
at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:103)
...
Caused by: org.springframework.messaging.MessagingException: At most one parameter (or expression via method-level @Payload) may be mapped to the payload or Message. Found more than one on method [public abstract java.util.List com.dao.PersonalinfoDao.queryExecute(java.lang.String,java.lang.String)]
at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.throwExceptionForMultipleMessageOrPayloadParameters(GatewayMethodInboundMessageMapper.java:235)
at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.access$400(GatewayMethodInboundMessageMapper.java:77)
at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper$DefaultMethodArgsMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:337)
...
波纹管显示我正在做什么来传递 2 个参数:
Bellow showing what I am doing for passing 2 parameters:
在我的 PersonalinfoDao.java
文件中,我有这个:
In my PersonalinfoDao.java
file I have this:
public interface PersonalinfoDao {
/** Method to call a SQL query using spring integration mechanism */
public List<PersonalInfo> queryExecute(String firstname, String lastname);
}
在我的 PersonalinfoService.java
文件中,我有:
In my PersonalinfoService.java
file I have this:
public class PersonalinfoService {
@Autowired
private PersonalinfoDao personalinfoDao;
public List<PersonalInfo> dbConnect(String firstname, String lastname) {
List<PersonalInfo> personalinfoList = personalinfoDao.queryExecute(firstname, lastname);
return personalinfoList;
}
}
在网关定义文件中,我有以下内容:
In Gateway definition file I have the following:
<!-- Mapper Declarations -->
<bean id="personalinfoMapper" class="com.support.PersonalinfoMapper"/>
<!-- Service Inheritance -->
<bean id="personalinfoService" class="com.service.PersonalinfoService"/>
<!-- Channels = For calling DAO interface methods in Spring Integration Mechanism one has to create request & response channels -->
<int:channel id="procedureRequestChannel"/>
<!-- Gateway = DAO Interface Method Mapped to Request & Response Channels -->
<int:gateway id="gateway_personalinfo" default-request-timeout="5000"
default-reply-timeout="5000"
service-interface="com.dao.PersonalinfoDao">
<int:method name="queryExecute" request-channel="procedureRequestChannel" />
</int:gateway>
<!-- Stored Procedure Outbound-Gateway = To call a database stored procedure -->
<int-jdbc:stored-proc-outbound-gateway id="outbound-gateway-storedproc-personalinfo"
request-channel="procedureRequestChannel"
data-source="dataSource"
stored-procedure-name="pkg_personalinfo_spring.proc_personalinfo_spring"
expect-single-result="true"
ignore-column-meta-data="true">
<!-- Parameter Definitions -->
<int-jdbc:sql-parameter-definition name="firstname" direction="IN"/>
<int-jdbc:sql-parameter-definition name="lastname" direction="IN"/>
<int-jdbc:sql-parameter-definition name="get_ResultSet" type="#{T(oracle.jdbc.OracleTypes).CURSOR}" direction="OUT"/>
<!-- Parameter Mappings Before Passing & Receiving -->
<int-jdbc:parameter name="firstname" expression="payload"/>
<int-jdbc:parameter name="lastname" expression="payload"/>
<int-jdbc:returning-resultset name="get_ResultSet" row-mapper="com.support.PersonalinfoMapper"/>
</int-jdbc:stored-proc-outbound-gateway>
我知道我在上面的网关定义中做错了什么,特别是在使用 expression="payload"
...因为对于任何给定的 Getway,我只能使用一个 payload代码>.但是由于我不清楚如何使用 Map/Array/List 来做到这一点,请问有人能帮我解决这个问题吗?
I know that i am doing something wrong in this above gateway definition specially when using expression="payload"
...because for any given Getway i can use only one payload
. But as I am not clear how to do that by using Map/Array/List, can any one plz help me to resolve this?
非常感谢你:)
推荐答案
可能最简单的方法是使用 @Payload
注释:
Probably the simplest way is to use a @Payload
annotation:
public interface PersonalinfoDao {
/** Method to call a SQL query using spring integration mechanism */
@Payload("#args")
public List<PersonalInfo> queryExecute(String firstname, String lastname);
}
或者在
的方法的 XML 声明中使用 payload-expression="#args"
.
Or use a payload-expression="#args"
in the XML declaration of the <gateway/>
's method.
然后框架会将有效载荷设为 Object[]
,您可以在其中使用 payload[0]
、payload[1]
等你的表情.
The framework will then make the payload an Object[]
and you can use payload[0]
, payload[1]
etc in your expressions.
这篇关于将 2/n 个(多个)参数传递给“int-jdbc:stored-proc-outbound-gateway"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!