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?

Mauro Molinari
  • 1,246
  • 2
  • 14
  • 24

1 Answers1

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 1
    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. – Mauro Molinari Oct 20 '21 at 07:41
  • 1
    I see what you mean - the other properties (e.g. requestChannel) work - it should work too https://github.com/spring-projects/spring-integration/issues/3648 – Gary Russell Oct 20 '21 at 14:14