Reputation: 23207
Currently I have several services making requests to other services.
In order to build the requests I'm using Spring RestTemplate
s.
Is there anyway to inject a RestTemplate initialized with some headers...?
I was thinking about Factory injectors.
Any ideas?
Upvotes: 1
Views: 77
Reputation: 38300
I think you are approaching the problem incorrectly.
Instead of injecting a RestTemplate
,
consider injecting an HttpEntity<?>
.
Setup the HttpEntity<?>
bean in your configuration @Bean
method.
Then use which ever RestTemplate.exchange()
method is appropriate to send your desired request.
Edits
The exchange
method sends an HTTP message and returns the response.
Here is the RestTemplate JavaDoc Page
Upvotes: 1