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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user