我可以使用哪个 bean 作为 http-outbound-gateway 的替代品?

Which bean can I use as a alternative one of http-outbound-gateway?

我正在将 spring-集成 3.x 更改为 4.x。 我应该将每个 xml 配置更改为 java 文件。

但是,我找不到可以替换以下内容的 bean。

<int-http:outbound-gateway url="http://www.google.com/ig/api?weather={city}"
                           http-method="GET"
                           expected-response-type="java.lang.String"
                           request-factory="requestFactory"
                           request-channel="requestChannel"
                           reply-channel="replyChannel">
    <int-http:uri-variable name="city" expression="payload"/>
</int-http:outbound-gateway>

<bean id="requestFactory"
      class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <property name="connectTimeout" value="5000"/>
    <property name="readTimeout"    value="5000"/>
</bean>

我尝试为此使用 HttpRequestExecutingMessageHandler。

@Bean
    HttpRequestExecutingMessageHandler httpGateway() {
        HttpRequestExecutingMessageHandler gateway 
        = new HttpRequestExecutingMessageHandler(gitlabUri);
        gateway.setOutputChannel(requestChannel());
        return gateway;
    }

但它没有请求通道作为参数。

帮帮我..

XML 解析器为出站端点创建 2 个 bean;一个 Consumer bean(事件驱动或可轮询,取决于输入通道类型)和注入到消费者中的消息处理程序。 ConsumerEndpointFactoryBean 用于生成合适的消费者。

因此,您可以自己连接 2 个 bean,或者使用 @ServiceActivator 注释,框架将负责为您创建消费者...

@ServiceActivator(input-channel="toHttp")
@Bean
HttpRequestExecutingMessageHandler httpGateway() {
    HttpRequestExecutingMessageHandler gateway 
        = new HttpRequestExecutingMessageHandler(gitlabUri);
    gateway.setOutputChannel(requestChannel());
    return gateway;
}

有关详细信息,请参阅 the reference manual。它以 HTTP 端点为例。