Netflix Eureka Server And Client Setup With Spring Boot


  • We will set up a Eureka server (service registry used to register multiple services/microservices).
  • We will set up multiple Eureka clients(REST services that register to Eureka Server).
  • We will do client-side load balancing and service discovery through Eureka.

Setting up Eureka Server

The dependency required to set up a eureka server is “spring-cloud-starter-netflix-eureka-client” along with spring-boot-starter-parent. you can generate the code by going to , and provide the group id, artifact id and provide the required dependencies as shown below, and click on generate which will generate the sample code with dependency added to your pom.xml

The corresponding pom.xml should look like the below

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
		<relativePath/> <!-- lookup parent from repository -->
	<description>Demo project for Spring Boot</description>







Once you have the project open the main Springboot Class with annotation @SpringbootApplication and add the annotation @EnableEurekaServer, the class should look like this.

package com.example.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class EurekaserverApplication {

	public static void main(String[] args) {, args);


The last step in setting up the server is adding the application.yml file which will have eureka relate properties when you start the application with @EnableEurekaServer annotation it will look for bootstrap.yml file if not found it will look for application.yml file for the properties the yml file should look something like this.

  port: 9090

    register-with-eureka: false
    fetch-registry: false
      defaultZone: http://localhost:9090/eureka/

The above properties yaml file defines the eureka defaultZone serviceUrl where eureka is supposed to run. register-with-eureka property is set to false as we don’t want to register Eureka Server to itself.
Once everything is the project structure should look like the below image

Go ahead and start the spring boot application, the eureka server should be up in whatever port you mentioned in application.yml file in this case eureka server will be up at localhost:9090 and will look like below.

Ola, we have set up the eureka server.

Now we will go ahead and create two clients named client1 and client2 from the spring initializer like the above with adding one more dependency Eureka Discovery Client, as shown below

Once we have both the projects created we will go ahead and add the annotation @EnableDiscoveryClient on the root SprintBootApplication class as shown below for both the clients Client1 and Client2

package com.example.client2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class Client2Application {

	public static void main(String[] args) {, args);


Similarly, we need to update the application.yml file as below providing the required eureka config details.

    name: 'client1'
  port: 8081

    hostname: ${vcap.application.uris[0]:localhost}
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 10
    lease-expiration-duration-in-seconds: 20
      defaultZone: http://localhost:9090/eureka

In the above code, we have provided the spring application name and eureka client service URL where the eureka server resides, so once you start the client it will look into the service URL and tries to register itself. The property lease-renewal-interval-in-seconds: 10 & lease-expiration-duration-in-seconds: 20 lets the Eureka Server when to check for the health of the client. Once you made these changes go ahead and start both the clients.

If you go back to Eureka Server you will now be able to see the two clients registered with names CLIENT1 and CLIENT2 as shown below.

Now the setup has been completed the two clients can talk to each with using the service discovery.

Here is the video tutorial explaining the same