如何传递参数@Payload
问题描述:
我有代码如何传递参数@Payload
<int:channel id="partnerConfigChannel" />
<int:gateway id="partnerService" service-interface="org.service.PartnerService"
\t \t default-request-timeout="5000" default-reply-timeout="5000">
\t \t <int:method name="findConfig" request-channel="partnerConfigChannel" />
</int:gateway>
<int-jpa:retrieving-outbound-gateway entity-manager="entityManager"
\t \t request-channel="partnerConfigChannel"
\t \t jpa-query="select q from QueueConfiguration q where q.partnerId = :partnerId">
\t \t <int-jpa:parameter name="partnerId" expression="payload['partnerId']" />
</int-jpa:retrieving-outbound-gateway>
和Java接口
public interface PartnerService {
@Payload("partnerId")
List<QueueConfiguration> findConfig();
}
我打电话它
List<QueueConfiguration> qc= partnerService.findConfig();
但我得到异常 EL1007E:(POS 0):属性或字段“PARTNERID”不能为null找到
请告诉我如何能够通过有效载荷。我尝试通过传递消息对象与地图,字符串,但同样的错误。 请告诉我如何在这种情况下通过有效载荷。
答
@Payload( “PARTNERID”)
此时,存在着对被评估为使用SpEL表达没有对象。
它要么必须是文字
@Payload("'partnerId'")
或者参考一些其他的bean。
此外,在您的适配器上,您希望有效负载是带有密钥partnerId
的地图。
expression="payload['partnerId']"
所以这是行不通的。
如果你想传递一个变量,你应该做这样的事情...
公共接口PartnerService {
List<QueueConfiguration> findConfig(MyClass param);
如果MyClass的有一些财产 'PARTNERID'。
或
List<QueueConfiguration> findConfig(String partnerId);
和
expression="payload"
我建议你做一些更多的reading。
答
我修改了代码
public interface PartnerService {
List<QueueConfiguration> findConfig(@Payload Message msg);
}
,并调用它像
Map msgMap=new HashMap();
msgMap.put("partnerId", partnerId);
Message msg=MessageBuilder.withPayload(msgMap).build();
List<QueueConfiguration> qc= partnerService.findConfig(msg);
,它是工作的罚款。
谢谢我用参数修改了代码。 –