I am using Spring Boot and want to use load balancer aware REST template. For this I created a Bean as follows
@LoadBalanced
@Bean
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
And created a REST client as follows:
@Component
public class EmployeeRestTemplateClient {
@Autowired
RestTemplate restTemplate;
public EmployeeResponseEntity getEmployeeByCode(String code) {
ResponseEntity<EmployeeResponseEntity> restExchange = restTemplate.exchange(
"http://employee/code/{code}",
HttpMethod.GET,
null,
EmployeeResponseEntity.class,
code
);
return restExchange.getBody();
}
}
I am using this REST client in my service to get data from another service. But when I hit the REST endpoint I get below exception
java.lang.ClassNotFoundException: org.springframework.cloud.client.loadbalancer.HttpRequestLoadBalancerRequest
I have the following dependency in my pom.xml file
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>3.1.3</version>
</dependency>
What am I missing?