【问题标题】:how to pass parameter @Payload如何传递参数@Payload
【发布时间】:2016-10-05 15:28:46
【问题描述】:

我有代码

<int:channel id="partnerConfigChannel" />
<int:gateway id="partnerService" service-interface="org.service.PartnerService"
		default-request-timeout="5000" default-reply-timeout="5000">
		<int:method name="findConfig" request-channel="partnerConfigChannel" />
</int:gateway>

<int-jpa:retrieving-outbound-gateway entity-manager="entityManager"
		 request-channel="partnerConfigChannel"
		jpa-query="select q from QueueConfiguration q where q.partnerId = :partnerId">
		<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): 在 null 上找不到属性或字段“partnerId”

请告诉我如何传递有效载荷。我尝试通过使用地图、字符串但相同的错误传递消息对象。 请告诉我在这种情况下如何传递有效载荷。

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    @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

    【讨论】:

      【解决方案2】:

      我修改了我的代码

      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);
      

      它工作正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-16
        • 1970-01-01
        • 2016-09-24
        • 2020-10-11
        • 1970-01-01
        相关资源
        最近更新 更多