Spring Boot- Using Spring Cloud Eureka Server

Eureka Server is an application that holds the information about all client-service applications.

Every Micro service will register into the Eureka server and Eureka server knows all the client applications running on each port and IP address. Eureka Server is also known as Discovery Server.

In this chapter, we will learn in detail about How to build a Eureka server.

Building a Eureka Server

Eureka Server comes with the bundle of Spring Cloud. For this, we need to develop the Eureka server and run it on the default port 8761.

Visit the Spring Initializer homepage https://start.spring.io/ and download the Spring Boot project with Eureka server dependency. It is shown in the screenshot below −

After downloading the project in main Spring Boot Application class file, we need to add @EnableEurekaServer annotation. 

The @EnableEurekaServer annotation is used to make your Spring Boot application acts as a Eureka Server.

The code for main Spring Boot application class file is as shown below −

package com.javahubpoint.eurekaserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

public class EurekaserverApplication {
   public static void main(String[] args) {
      SpringApplication.run(EurekaserverApplication.class, args);

Make sure Spring cloud Eureka server dependency is added in your build configuration file.

The code for Maven user dependency is shown below −


The code for Gradle user dependency is given below −


The complete build configuration file is given below −

Maven pom.xml

<?xml version = "1.0" encoding = "UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 
   <description>Demo project for Spring Boot</description>
      <relativePath/> <!-- lookup parent from repository -->

Gradle – build.gradle

buildscript {
   ext {
      springBootVersion = '1.5.9.RELEASE'
   repositories {
   dependencies {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.javahubpoint'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
ext {
   springCloudVersion = 'Edgware.RELEASE'
dependencies {
dependencyManagement {
   imports {
      mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"

By default, the Eureka Server registers itself into the discovery. You should add the below given configuration into your application.properties file or application.yml file.

application.properties file is given below −

eureka.client.registerWithEureka = false
eureka.client.fetchRegistry = false
server.port = 8761

The application.yml file is given below −

      registerWithEureka: false
      fetchRegistry: false
   port: 8761

Now, you can create an executable JAR file, and run the Spring Boot application by using the Maven or Gradle commands shown below −

For Maven, use the command as shown below −

mvn clean install

After “BUILD SUCCESS”, you can find the JAR file under the target directory.

For Gradle, you can use the command shown below −

gradle clean build

After “BUILD SUCCESSFUL”, you can find the JAR file under the build/libs directory.

Now, run the JAR file by using the following command −

 java –jar <JARFILE> 

You can find that the application has started on the Tomcat port 8761 as shown below −

Now, hit the URL http://localhost:8761/ in your web browser and you can find the Eureka Server running on the port 8761 as shown below −