Step-by-Step Guide to Setting Up Eureka Server and Client in Spring Boot

Table of contents
- Why Choose Eureka for Your Microservices?
- Understanding the Role of Eureka Server
- Step-by-Step: Creating Your Eureka Server
- Configuring Your Eureka Server for Success
- Launching Your Eureka Server: A Quick Guide
- What Makes Eureka Client Essential?
- Building Your Eureka Client: A Step-by-Step Guide
- Setting Up Your Eureka Client for Optimal Performance
- Running Your Eureka Client: A Simple Walkthrough
- Final Thoughts: Enhancing Service Communication with Eureka

Why Choose Eureka for Your Microservices?
Eureka offers several advantages for microservices architecture:
Dynamic discovery: Instead of relying on hard-coded URLs and ports, clients can dynamically look up services by name at runtime, enabling more flexible deployments.
Automatic scaling: Service instances can be added or removed automatically, facilitating seamless scaling.
Resilience: Eureka manages health checks and load balancing across healthy service instances, enhancing system reliability.
High availability: Eureka Servers can replicate with peers, ensuring clients can failover to healthy registry servers, minimizing downtime.
Integration: Eureka integrates seamlessly with the Spring Cloud Netflix ecosystem, including Ribbon and Actuator, for efficient load balancing and service status monitoring.
Understanding the Role of Eureka Server
Eureka Server is a service registry and discovery server developed by Netflix; it is part of Spring Cloud. It works by acting like a phone book for your microservice, keeping track of where each service instance is located by IP & Port, so that others can find and communicate with them dynamically.
Step-by-Step: Creating Your Eureka Server
To begin, we'll create a Spring Boot project for the base of Eureka Server. We’ll use Spring Initializr for this tutorial.“. Go to https://start.spring.io/ and let’s begin initializing our Eureka Server.
Here’s the configuration we’ll use:
Project - Maven
Language - Java 17
Spring Boot - 3.5.3
Packaging - Jar
dependencies required to configure the server correctly are:
- Eureka Server
Now generate the Spring application and open it in your IDE of choice. open it in your IDE of choice; we'll use IntelliJ in this tutorial.
Configuring Your Eureka Server for Success
Now with the project open go to your pom.xml and verify that you have the following dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Those dependencies are what we initialized in the Spring initialzr and are needed to configure our server properly. These dependencies contain the methods and the beans for which we need.
Now let’s go to our main Eureka Server Main application class. In this file we will use the “@EnableEurekaServer” annotation. With this annotation, Spring Boot will configure and manage our server dynamically.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class, args);
}
}
It’s a good time to configure our application.properties file with the values we need to run the Eureka Server. Inside our application.properties we'll start by configuring a few general properties. We will give our application a name to be associated by. Next, we specify the port number—even though Eureka defaults to “8761”, it's good practice to include it.
Finally we will configure the properties related to Eureka Server. The properties we will define are listed in the code snippet below.
spring.application.name=eureka-service
server.port=8761
#properties for eureka server
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.instance.hostname=localhost
From top to bottom, the properties are:
eureka.client.register-with-eureka
eureka.client.fetch-registry
eureka.instance.hostname
We have “eureka.client.register-with-eureka” & “eureka.client.fetch-registry” set to false because the server doesn’t need to register with Eureka Server because it is the server. Fetching isn’t necessary because this is the registry. Last we have “eureka.instance.hostname“ which is set to localhost because I’m running the application locally. It's optional, but I include it for clarity.
Launching Your Eureka Server: A Quick Guide
There are multiple ways to run the application but for simplicity we’ll click the “Run” button in the IntelliJ toolbar. Or you can use the keyboard shortcut “Shift + F10” in IntelliJ. Now that the server is up and running, now go to the browser and in the URL enter “http://localhost:8761”. This is the location of our Eureka Server. You should see the following:
Now that we have our server up and running we now need to create a client to register to on our Eureka Server.
What Makes Eureka Client Essential?
A Eureka Client is any Spring Boot application that connects to a Eureka Server for service discovery. Once configured, it does two main things. First registers itself with the Eureka Server as an instance so other services can find and call it. Lastly it discovers other services by querying the registry and allowing dynamic retrieval of service endpoints instead of hard coding them.
Building Your Eureka Client: A Step-by-Step Guide
To create a Eureka Client we will follow some of the same steps from when we created the Eureka Server. Let’s head back to Spring Initializr: https://start.spring.io/ & setup the Eureka Client. Here’s the configuration we’ll use:
Project - Maven
Language - Java 17
Spring Boot Version - 3.5.3
Packaging - Jar
The dependencies required to configure our client correctly are:
Eureka Discovery Client
Spring Web
Now generate the Spring application and open it in your IDE of choice. We will be using IntelliJ for this tutorial.
Setting Up Your Eureka Client for Optimal Performance
Now with the project open go to your pom.xml and verify that you have the following dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Those dependencies are what we initialized in the Spring initialzr and are needed to configure our client properly. These dependencies contain the methods and the beans for which we need.
Now let’s go to our main Eureka Client Main application class. In this file we will use the “@EnableDiscoveryClient” annotation. With this annotation Spring boot will allow our application to register to the service registry, also it will make our client discoverable by other services( need to use open feign client or @loadbalanced rest template).
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(GameServiceApplication.class, args);
}
}
Now let's configure the application.properties file with the properties needed to run our Eureka Client. Just like in the our server application.properties we have a couple general properties. We will give our application a name to be associated by. Next will specify our port number which is “8081”. Not required because Spring Boot defaults to port “8080”. But if you plan on running multiple applications at once locally you need to specify a different port for your other applications. The reason being is that only one application can run on a single port.
Finally we will configure the properties related to Eureka Server. The properties we will define are listed in the code snippet below.
spring.application.name=eureka-client
server.port=8081
#properties for eureka server
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
From top to bottom, the properties are:
eureka.client.register-with-eureka
eureka.client.fetch-registry
eureka.client.serviceUrl.defaultZone
We have “eureka.client.register-with-eureka” & “eureka.client.fetch-registry” both set to true because the client needs to register with our Eureka Server so that other services can discover this service(client). Also we have to fetch the registry because that’s how our services know about the other services within this registry. Last we have “eureka.client.serviceUrl.defaultZone“. In a nutshell this property tells your client/service where the Eureka server is located so it can register and fetch the registry.
Running Your Eureka Client: A Simple Walkthrough
Make sure your Eureka Server is still running or start it. Like I stated before there are multiple ways to run an application but we will use the run button looked at the top-nav in IntelliJ IDE. Or you can use the keyboard shortcut “Shift + F10” in IntelliJ. Now that the server and client are both are running, navigate to “http://localhost:8761”.
- This is the location of our Eureka Server. Under “Instances currently registered with Eureka,” you should see “EUREKA‑CLIENT” listed as UP..
Final Thoughts: Enhancing Service Communication with Eureka
Congratulations! You have successfully created your eureka client and server now you can communicate between services more dynamically without hard‑coding URLs (using RestTemplate or OpenFeign). Thank you for your time, I hope you learned something new. If you enjoyed this post, please share your thoughts. Until next time, see you all later!
Subscribe to my newsletter
Read articles from Delijhia Brown directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
