Change in contract for @LoadBalanced

Users now need to create their own bean and qualify it, and Spring
Cloud will customize it (instead of providing the @Bean itself).

This is much better for users, since they remain in control of the
bean declarations, and can choose which one (if any) is @Primary.
It's a breaking change for some apps (if they rely on a
@LoadBalanced RestTemplate being automatically injected).
This commit is contained in:
Dave Syer
2016-03-07 17:44:41 +00:00
parent 7eccbc4bac
commit ad08ca55f4
3 changed files with 127 additions and 94 deletions

View File

@@ -318,15 +318,21 @@ for details of how the `RestTemplate` is set up.
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`.
the `@LoadBalanced` qualifier when you create your `@Bean`.
IMPORTANT: Notice the `@Primary` annotation on the plain `RestTemplate` declaration.
IMPORTANT: Notice the `@Primary` annotation on the plain `RestTemplate` declaration in the example below, to disambiguate the unqualified `@Autowired` injection.
[source,java,indent=0]
----
@Configuration
public class MyConfiguration {
@LoadBalanced
@Bean
RestTemplate loadBalanced() {
return new RestTemplate();
}
@Primary
@Bean
RestTemplate restTemplate() {