Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #35 from microservices-demo/bug/resttemplatebean
Browse files Browse the repository at this point in the history
moved template to Bean so it can be intercepted by sleuth
  • Loading branch information
moretea authored Jan 4, 2017
2 parents 5aa456e + d4159fb commit 85c4e63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.net.InetSocketAddress;
Expand All @@ -15,7 +17,12 @@
public final class RestProxyTemplate {
private final Logger logger = LoggerFactory.getLogger(getClass());

private RestTemplate restTemplate = new RestTemplate();
@Autowired RestTemplate restTemplate;

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

@Value("${proxy.host:}")
private String host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<
InterruptedException, IOException {
RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
LOG.debug("Requesting: " + request.toString());
Resource<T> body = halTemplate.exchange(request, type).getBody();
Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
LOG.debug("Received: " + body.toString());
return new AsyncResult<>(body);
}
Expand Down

0 comments on commit 85c4e63

Please sign in to comment.