Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to use preconfigured RestTemplate instance by default in HttpRequestExecutingMessageHandler [INT-4460] #8401

Closed
spring-operator opened this issue May 3, 2018 · 2 comments
Assignees
Labels

Comments

@spring-operator
Copy link
Contributor

Vyacheslav opened INT-4460 and commented

Currently HttpRequestExecutingMessageHandler creates new instance of RestTemplate if no one specified explicitly.

It may be more convenient to use preconfigured RestTemplate bean in current ApplicationContext. If there no RestTemplate beans then default to new instance.

Example:

@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(...);
        return restTemplate;
    }

}
@Configuration
public class TestFlowConfig {

    @Bean
    public IntegrationFlow test() {
        return IntegrationFlows.from(Http.inboundGateway("/test"))
            .handle(Http.outboundGateway("http://127.0.0.1/test")); // implicitly uses RestTemplate declared in RestTemplateConfig
            .get();
    }

}

Affects: 5.0.4

@spring-operator
Copy link
Contributor Author

Artem Bilan commented

How about this solution so far?

@Autowired
private RestTemplate restTemplate;
...
private HttpMessageHandlerSpec httOutboundGateway(String uri) {
	return Http.outboundGateway(uri, this.restTemplate);
}
...
@Bean
public IntegrationFlow test() {
     return IntegrationFlows.from(Http.inboundGateway("/test"))
           .handle(httOutboundGateway("http://127.0.0.1/test")); 
           .get();
}

The problem that make me reluctant to implement your request is that Spring Integration components don't do any auto-injection magic for user-defined beans. Plus this HttpRequestExecutingMessageHandler is a bit complex component to break it for potential auto-injection. Also pay attention how its restTemplate property is final. That's another argument do not implement auto-injection - for performance reason at runtime.

@spring-operator
Copy link
Contributor Author

Artem Bilan commented

As we discussed we are not going to introduce any auto-injection complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants