问题
I have configured timeouts for the HTTP Outbound Gateway providing a reference to a ClientHttpRequestFactory bean using the request-factory attribute:
<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>
But I want to load these attributes dynamically from DDBB (or programmatically) and not from Spring initial boot.
How can I do this?
回答1:
Programmatically you can do that just from any your service injecting that requestFactoryGetByCustomer
bean and using its setters:
@Autowired
private SimpleClientHttpRequestFactory requestFactoryGetByCustomer;
....
this.requestFactoryGetByCustomer.setConnectTimeout(30_000);
To read those options from the DB and populate them to the bean definition using Spring Container features (e.g. Property Placeholder like in your current case) you should take a look to the Commons Configuration framework and populate Properties
object from the DB SELECT
.
来源:https://stackoverflow.com/questions/31793760/timeout-dynamic-http-outbound-gateway-request-factory