超时动态 HTTP 出站网关请求工厂

timeout dynamic HTTP outbound gateway request-factory

我已经为使用请求工厂属性提供对 ClientHttpRequestFactory bean 的引用的 HTTP 出站网关配置了超时:

<int-http:outbound-gateway request-channel="channelGetByCustomer"
    request-factory="requestFactoryGetByCustomer"
    reply-channel="jsonToObjectChannel" url="${getbycustomer.endpoint.url}"
    http-method="GET" expected-response-type="com.mbracero.integration.dto.Item[]">

    <int-http:uri-variable name="customerid" expression="payload.customerid"/>

</int-http:outbound-gateway>

<beans:bean id="requestFactoryGetByCustomer" class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <beans:property name="connectTimeout" value="${getbycustomer.timeout}"/>
    <beans:property name="readTimeout" value="${getbycustomer.timeout}"/>
</beans:bean>

但我想从 DDBB(或以编程方式)动态加载这些属性,而不是从 Spring 初始启动。

我该怎么做?

以编程方式,您可以通过注入该 requestFactoryGetByCustomer bean 并使用其设置器的任何服务来做到这一点:

@Autowired
private SimpleClientHttpRequestFactory requestFactoryGetByCustomer;

....

this.requestFactoryGetByCustomer.setConnectTimeout(30_000);

要从数据库中读取这些选项并使用 Spring 容器功能(例如 属性 占位符,就像您当前的情况)将它们填充到 bean 定义中,您应该查看 Commons Configuration 框架并从数据库 SELECT.

填充 Properties 对象