【问题标题】:@Gateway is not required if we use @MessagingGateway如果我们使用@MessagingGateway,则不需要@Gateway
【发布时间】:2020-06-17 11:58:34
【问题描述】:

从 Spring 4.0 开始,引入了 @MessagingGateway。如果我们的网关接口中只有一个网关方法,则使用它,那么我们不需要用@Gateway 注释网关方法。 下面是我的示例,两者都在工作。

那么,我的问题是,当我们在网关接口中只有一种方法时,我们可以停止使用@Gateway 吗?

代码 1:

@MessagingGateway(name="demoGateway")
public interface DemoGateway {
    @Gateway(requestChannel = "gatewayRequestChannel",replyChannel = "nullChannel")
    void accept(Message<String> request);
}

代码 2:

@MessagingGateway(name="demoGateway",defaultRequestChannel = 
"gatewayRequestChannel",defaultReplyChannel = "nullChannel")
public interface DemoGateway {

    void accept(Message<String> request);
}

【问题讨论】:

    标签: spring spring-boot spring-integration spring-integration-dsl


    【解决方案1】:

    是的。你说的对。您可以执行方法 2,并将确认的单个方法保留为 @MessagingGateway 的默认配置而无需注释。

    但在实践中,我只会将真正的默认值移动到MessagingGateway,而将其他值留给@Gateway 注释。

    这是因为如果您将来必须向DemoGateway 添加更多方法,它会使将来的生活和可读性更容易。

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 2021-02-22
      • 1970-01-01
      • 2018-11-24
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多