@Gateway(payloadExpression="..") vs @Payload("...")
Asked Answered
I

1

1

Spring integration documentation explains that a payload expression must be specified when declaring a gateway from an interface method with no arguments, so that the framework knows what payload should be set on the generated message. However, if I do the following:

<int:gateway id="myGateway"
  service-interface="com.example.MyGateway"
  default-request-channel="requestChannel"
  default-reply-channel="replyChannel" />

for the following interface:

package com.example;
public interface MyGateway {

    @Gateway(payloadExpression = "''")
    String doSomething();
}

this leads to an error: "receive is not supported, because no pollable reply channel has been configured".

This works instead:

public interface MyGateway {

    @Payload("''")
    String doSomething();
}

Indeed, the same above documentation specifies that the payload should be specified with either @Payload or with payload-expression attribute on method elements. However, as a user, I find it quite surprising that setting a payload expression through the @Gateway annotation does not work here, especially because the same annotation works in other contexts.

Is this on purpose or an oversight?

Incursion answered 19/10, 2021 at 14:23 Comment(0)
B
0

It is not clear why the documentation is confusing, but feel free to suggest improvements.

The @Gateway annotation is intended for configuration when using annotation-based configuration

https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/messaging-endpoints.html#gateway-configuration-annotations

The docs clearly state to use @Payload or payload-expression when using XML configuration.

Burlingame answered 19/10, 2021 at 14:46 Comment(2)
I've not said the documentation is confusing, I said that the behaviour is surprising. I have other projects in which I declare my gateway in XML with a simple declaration like the above, then I annotate multiple methods within that interface with @Gateway and this works perfectly fine. It seems like the problem occurs when such interface has just one method, in which case probably @Gateway is simply ignored, or at least its payloadExpression value. Compare the behaviour with transformers: it's perfectly fine to declare a transformer in XML and use @Transformer to specify which method.Incursion
I see what you mean - the other properties (e.g. requestChannel) work - it should work too github.com/spring-projects/spring-integration/issues/3648Burlingame

© 2022 - 2025 — McMap. All rights reserved.