【问题标题】:How can I create http outbound-gateway with JAVA config in Spring integration?如何在 Spring 集成中使用 JAVA 配置创建 http 出站网关?
【发布时间】:2016-07-03 12:23:15
【问题描述】:

我有以下 http 出站网关。如何使用 Java Config 或 Spring DSL 进行此配置?

<int-http:outbound-gateway id="test"
                           url="http://localhost:8080/"
                           http-method="POST"
                           charset="UTF-8"
                           header-mapper="soapHeaderMapper"
                           request-factory="requestFactory"
                           request-channel="inputChannel"/>

【问题讨论】:

    标签: java spring spring-integration


    【解决方案1】:
    @Bean
    public IntegrationFlow httpOut() {
        return IntegrationFlows.from("inputChannel")
                .handle(Http.outboundGateway("http://localhost:8080/")
                        .charset("UTF-8")
                        .httpMethod(HttpMethod.POST)
                        .headerMapper(soapHeaderMapper())
                        .requestFactory(requestFactory()), e -> e.id("test"))
                .get();
    }
    

    或者

    @ServiceActivator(inputChannel="inputChannel")
    @Bean(name="test")
    public MessageHandler httpout() {
        HttpRequestExecutingMessageHandler handler = new ...
        ...
        return handler;
    }
    

    【讨论】:

    • 如何决定哪一个更好?我希望两者都提供类似的定制并提供类似的可读性。有什么想法吗?
    • 大多数人更喜欢 java DSL(第一个)或 XML 而不是注释模型。在运行时,所有 3 种方法之间没有区别。所以这完全取决于用户偏好。
    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多