Feign helps us create REST clients for REST services with minimum configuration and code. All you need to define is a simple interface and use proper annotations.
RestTemplate
is typically used to make REST service calls. Feign helps us write REST clients without the need for RestTemplate
and the logic around it.
Feign integrates well with Ribbon (client-side load balancing) and Eureka (Name server). We will look at this integration later in the chapter.
To use Feign, let's add the Feign starter to the pom.xml
file of service consumer microservice:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency>
We need to add dependencyManagement
for Spring Cloud to the pom.xml
file as this is the first Cloud dependency that service consumer microservice is using:
<dependencyManagement> <dependencies> <dependency...