以下示例说明如何使用 Java 配置入站网关:Spring中文文档

使用 Java 配置的入站网关
@Bean
public HttpRequestHandlingMessagingGateway inbound() {
    HttpRequestHandlingMessagingGateway gateway =
        new HttpRequestHandlingMessagingGateway(true);
    gateway.setRequestMapping(mapping());
    gateway.setRequestPayloadType(String.class);
    gateway.setRequestChannelName("httpRequest");
    return gateway;
}

@Bean
public RequestMapping mapping() {
    RequestMapping requestMapping = new RequestMapping();
    requestMapping.setPathPatterns("/foo");
    requestMapping.setMethods(HttpMethod.POST);
    return requestMapping;
}

以下示例演示如何使用 Java DSL 配置入站网关:Spring中文文档

使用 Java DSL 的入站网关
@Bean
public IntegrationFlow inbound() {
    return IntegrationFlow.from(Http.inboundGateway("/foo")
            .requestMapping(m -> m.methods(HttpMethod.POST))
            .requestPayloadType(String.class))
        .channel("httpRequest")
        .get();
}

以下示例说明如何使用 Java 配置出站网关:Spring中文文档

使用 Java 配置的出站网关
@ServiceActivator(inputChannel = "httpOutRequest")
@Bean
public HttpRequestExecutingMessageHandler outbound() {
    HttpRequestExecutingMessageHandler handler =
        new HttpRequestExecutingMessageHandler("http://localhost:8080/foo");
    handler.setHttpMethod(HttpMethod.POST);
    handler.setExpectedResponseType(String.class);
    return handler;
}

以下示例演示如何使用 Java DSL 配置出站网关:Spring中文文档

使用 Java DSL 的出站网关
@Bean
public IntegrationFlow outbound() {
    return IntegrationFlow.from("httpOutRequest")
        .handle(Http.outboundGateway("http://localhost:8080/foo")
            .httpMethod(HttpMethod.POST)
            .expectedResponseType(String.class))
        .get();
}