From bfd25e1d502dae860051e02c8172d71eda854014 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 2 Mar 2016 19:02:43 -0700 Subject: [PATCH] Document @Primary for plain RestTemplate beans. fixes gh-60 --- docs/src/main/asciidoc/spring-cloud-commons.adoc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-commons.adoc b/docs/src/main/asciidoc/spring-cloud-commons.adoc index 13856166..63c265c0 100644 --- a/docs/src/main/asciidoc/spring-cloud-commons.adoc +++ b/docs/src/main/asciidoc/spring-cloud-commons.adoc @@ -317,11 +317,23 @@ for details of how the `RestTemplate` is set up. === Multiple RestTemplate objects If you want a `RestTemplate` that is not load balanced, create a `RestTemplate` -bean and inject it as normal. To access the load balanced `RestTemplate use -the provided `@LoadBalanced` `Qualifier`: +bean and inject it as normal. To access the load balanced `RestTemplate use +the provided `@LoadBalanced` `Qualifier`. + +IMPORTANT: Notice the `@Primary` annotation on the plain `RestTemplate` declaration. [source,java,indent=0] ---- +@Configuration +public class MyConfiguration { + + @Primary + @Bean + RestTemplate restTemplate() { + return new RestTemplate(); + } +} + public class MyClass { @Autowired private RestTemplate restTemplate;