我已经为 HTTP 出站网关配置了超时,使用 request-factory 属性提供对 ClientHttpRequestFactory bean 的引用:
<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 初始启动。
我该怎么做?
最佳答案
以编程方式,您可以通过注入(inject) requestFactoryGetByCustomer
bean 并使用其 setter 的任何服务来做到这一点:
@Autowired
private SimpleClientHttpRequestFactory requestFactoryGetByCustomer;
....
this.requestFactoryGetByCustomer.setConnectTimeout(30_000);
要从数据库中读取这些选项并使用 Spring 容器功能(例如当前情况下的属性占位符)将它们填充到 bean 定义中,您应该查看 Commons Configuration
框架并从数据库 SELECT
填充 Properties
对象。
关于java - 超时动态 HTTP 出站网关请求工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31793760/