Microservices – Client Side Load Balancing

To enable client side load balancing, @LoadBalanced annotation can be used on RestTemplate.

@Bean
@LoadBalanced
public RestTemplate getRestTemplate() {
	return new RestTemplate();
}

Note: Do not use @LoadBalanced annotation if you are using hard-coded URLs for Development or Testing purpose otherwise exception will be thrown.
It is required to use @LoadBalanced annotation if you are using service ids instead of hard-coded URLs.

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.