diff --git a/src/main/java/works/weave/socks/orders/config/RestProxyTemplate.java b/src/main/java/works/weave/socks/orders/config/RestProxyTemplate.java index 6d28831..174bb9a 100644 --- a/src/main/java/works/weave/socks/orders/config/RestProxyTemplate.java +++ b/src/main/java/works/weave/socks/orders/config/RestProxyTemplate.java @@ -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; @@ -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; diff --git a/src/main/java/works/weave/socks/orders/services/AsyncGetService.java b/src/main/java/works/weave/socks/orders/services/AsyncGetService.java index dc49cc1..901c621 100644 --- a/src/main/java/works/weave/socks/orders/services/AsyncGetService.java +++ b/src/main/java/works/weave/socks/orders/services/AsyncGetService.java @@ -56,7 +56,7 @@ public Future> getResource(URI url, TypeReferences.ResourceType< InterruptedException, IOException { RequestEntity request = RequestEntity.get(url).accept(HAL_JSON).build(); LOG.debug("Requesting: " + request.toString()); - Resource body = halTemplate.exchange(request, type).getBody(); + Resource body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); LOG.debug("Received: " + body.toString()); return new AsyncResult<>(body); }