Reputation: 843
From Spring 4.0 onwards @MessagingGateway
was introdued. Using it if we have only one gateway method in our Gateway interface , then we don't need to annotate the Gateway method with @Gateway
.
Below is my example, where both are working.
So, my question is can we stop using @Gateway
when we have only one method in Gateway interface?
Code-1:
@MessagingGateway(name="demoGateway")
public interface DemoGateway {
@Gateway(requestChannel = "gatewayRequestChannel",replyChannel = "nullChannel")
void accept(Message<String> request);
}
Code-2:
@MessagingGateway(name="demoGateway",defaultRequestChannel =
"gatewayRequestChannel",defaultReplyChannel = "nullChannel")
public interface DemoGateway {
void accept(Message<String> request);
}
Upvotes: 0
Views: 638
Reputation: 8203
Yes. You are right. You can do approach 2 and leave the single method that confirms to the default configuration of @MessagingGateway
without annotation.
However in practice, I will only move the truly default values to the MessagingGateway
and leave other values to @Gateway
annotation.
This is because it makes life and readability easier in the future if you have to add more methods to DemoGateway
in the future.
Upvotes: 2