如何在 Spring 集成中使用 JAVA 配置创建 http 入站通道适配器?

How can I create http inbound channel adapter with JAVA config in Spring integration?

我有以下 http 入站通道适配器。如何使用 Java Config 或 Spring DSL 进行此配置?

<int-http:inbound-channel-adapter
    channel="api_app_integration_request_channel" 
    supported-methods="PUT" 
    path="/process/ticket"
    request-payload-type="*.model.Ticket"
    header-mapper="headerMapper"
    error-channel="internal-client-rest-ticket-error-channel"
>
<int-http:request-mapping consumes="application/json" />
</int-http:inbound-channel-adapter>

参见Spring集成参考手册:

Java DSL:https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl

HTTP 模块细节:https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-java-config

您的特定样本可以翻译成这个 IntegrationFlow:

    @Bean
    public IntegrationFlow myHttpFlow() {
        return IntegrationFlows
                .from(Http.inboundChannelAdapter("/process/ticket")
                        .requestMapping(r -> r
                                .methods(HttpMethod.PUT)
                                .consumes("application/json"))
                        .requestPayloadType(model.Ticket.class)
                        .headerMapper(headerMapper))
                .channel("api_app_integration_request_channel")
                ...
                .get();
    }

您可以添加集成端点来构建处理这些请求的逻辑,而不是 ...

在同一 HTTP 章节中,您可以找到如何将 HttpRequestHandlingMessagingGateway 配置为普通 @Bean