Spring Boot and Netflix Eureka Integration

In this post we will learn how to integrate applications developed in Spring Boot with Netflix Eureka.

First step is to create two Spring Boot application services

  • customer-service
  • order-service

Go to https://start.spring.io and create order-service app using below config details.

Mainly for our use case, adding Spring Web, Eureka Server dependencies are the required ones

Likewise, create customer-service app with same config details used for order-service by adding Spring Web, Eureka Server dependencies.

Next, create eureka-server app with below config . Adding Eureka Server is main important config for our use case

Next, Import the projects created from the above into Eclipse IDE.

Add @EnableEurekaServer on EurekaServerApplication class as shown Below

package com.venkat;

public class EurekaServerApplication {

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

Add below properties to the application.properties


Next, Add @EnableEurekaClient on CustomerServiceApplication class in customer-service  app as shown below

public class CustomerServiceApplication {
public static void main(String[] args) throws RestClientException, IOException {
SpringApplication.run(CustomerServiceApplication.class, args);

public ConsumerControllerClient consumerControllerClient()
return new ConsumerControllerClient();

Likewise, Add @EnableEurekaClient on OrderServiceApplication class in order-service app as shown below

public class OrderSerivceApplication {

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

Next, Add below configuration in customer-service and order-service
application.properties files





Next, Create Order.java in model package as shown below with orderId, itemName, itemType, Cost attributes.

package com.venkat.model;

public class Order {
private String orderId;
private String itemName;
private String itemType;
private double cost;

public Order() {

public String getOrderId() {
return orderId;

public void setOrderId(String orderId) {
this.orderId = orderId;

public String getItemName() {
return itemName;

public void setItemName(String itemName) {
this.itemName = itemName;

public String getItemType() {
return itemType;

public void setItemType(String itemType) {
this.itemType = itemType;

public double getCost() {
return cost;

public void setCost(double cost) {
this.cost = cost;

Create OrderController with a REST GET mapping for /customerorder to return Order object

package com.venkat.controllers;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.venkat.model.Order;

public class OrderController {

@RequestMapping(value = "/customerorder", method = RequestMethod.GET)
public Order customerOrder() {
Order order = new Order();
return order;

Create a ConsumerControllerClient.java class as shown below

package com.venkat.controllers;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

public class ConsumerControllerClient {

private DiscoveryClient discoveryClient;

public String getCustomerOrder() throws RestClientException, IOException {

List<ServiceInstance> instances = discoveryClient.getInstances("ORDER-SERVICE");

// Creating URL for calling order-service
ServiceInstance serviceInstance = instances.get(0);
String baseURL = serviceInstance.getUri().toString();
String completeURL = baseURL + "/customerorder";

// Calling order-service
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = null;
try {
response = restTemplate.exchange(completeURL, HttpMethod.GET, getHeaders(), String.class);
} catch (Exception ex) {
return response.getBody();

private static HttpEntity<?> getHeaders() throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
return new HttpEntity<>(headers);


Final step is to Run EurekaServer, order-service, customer-service apps

Open http://localhost:8090 (port on which eureka server is running). Here you will see
order-service,customer-service app instances registered with it.

Output on hitting REST Endpoint http://localhost:8091/customerorderinfo is given below


In the above post we have seen how to register two service applications with Netflix Eureka
Server and communicate between the services via Eureka server registry without knowing the
host, port info of the service to which we are communicating with.

Spring Boot Starter dependencies

Spring Boot provides a number of starters which allow us to add jars in the classpath. Spring Boot Starters are the dependency descriptors. Spring Boot built-in starters make development easier, rapid and easily maintainable.

Naming Pattern

In the Spring Boot framework, all the starters follow a similar naming pattern: spring-boot-starter-*, where * denotes a particular type of application.

Example, if we require to use Spring and JPA for database access, spring-boot-starter-data-jpa dependency in our pom.xml file of the project can be included.


If we are developing REST API, spring-boot-starter-web dependency can be used.


If gradle is being used as build tool, then following can be added to build.gradle file in the project.

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'

Below are the jars which are added to project’s classpath on adding “spring-boot-starter-data-jpa”

Spring Boot Starters can be broadly classified into three categories

  1. Production Starters
  2. Application Starters
  3. Technical Starters

Below is complete list of the starters available in above categories

Spring Boot Production Starters



spring-boot-starter-actuator This provides production-ready features to help you monitor and manage your application.
spring-boot-starter-remote-shell This is used for the CRaSH remote shell to monitor and manage your application over SSH. Deprecated since 1.5.

Spring Boot Application Starters



spring-boot-starter-thymeleaf For building MVC web applications using Thymeleaf views.
spring-boot-starter-data-couchbase For the Couchbase document-oriented database and Spring Data Couchbase.
spring-boot-starter-artemis For JMS messaging using Apache Artemis.
spring-boot-starter-web-services For Spring Web Services.
spring-boot-starter-mail To support Java Mail and Spring Framework’s email sending.
spring-boot-starter-data-redis Used for Redis key-value data store with Spring Data Redis and the Jedis client.
spring-boot-starter-web For building the web application, including RESTful applications using Spring MVC. It uses Tomcat as the default embedded container.
spring-boot-starter-data-gemfire Used to GemFire distributed data store and Spring Data GemFire.
spring-boot-starter-activemq For JMS messaging using Apache ActiveMQ.
spring-boot-starter-data-elasticsearch For Elasticsearch search and analytics engine and Spring Data Elasticsearch.
spring-boot-starter-integration It is used for Spring Integration.
spring-boot-starter-test Used to test Spring Boot applications with libraries, including JUnit, Hamcrest, and Mockito.
spring-boot-starter-jdbc Used for JDBC with the Tomcat JDBC connection pool.
spring-boot-starter-mobile Used for building web applications using Spring Mobile.
spring-boot-starter-validation Used for Java Bean Validation with Hibernate Validator.
spring-boot-starter-hateoas Used to build a hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS.
spring-boot-starter-jersey Used to build RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web.
spring-boot-starter-data-neo4j Used for the Neo4j graph database and Spring Data Neo4j.
spring-boot-starter-data-ldap Used for Spring Data LDAP.
spring-boot-starter-websocket Used for building the WebSocket applications. It uses Spring Framework’s WebSocket support.
spring-boot-starter-aop For aspect-oriented programming with Spring AOP and AspectJ.
spring-boot-starter-amqp For Spring AMQP and Rabbit MQ.
spring-boot-starter-data-cassandra For Cassandra distributed database and Spring Data Cassandra.
spring-boot-starter-social-facebook For Spring Social Facebook.
spring-boot-starter-jta-atomikos For JTA transactions using Atomikos.
spring-boot-starter-security It is used for Spring Security.
spring-boot-starter-mustache It is used for building MVC web applications using Mustache views.
spring-boot-starter-data-jpa Used for Spring Data JPA with Hibernate.
spring-boot-starter Used for core starter, including auto-configuration support, logging, and YAML.
spring-boot-starter-groovy-templates Used for building MVC web applications using Groovy Template views.
spring-boot-starter-freemarker It is used for building MVC web applications using FreeMarker views.
spring-boot-starter-batch For Spring Batch.
spring-boot-starter-social-linkedin For Spring Social LinkedIn.
spring-boot-starter-cache For Spring Framework’s caching support.
spring-boot-starter-data-solr It is used for the Apache Solr search platform with Spring Data Solr.
spring-boot-starter-data-mongodb It is used for MongoDB document-oriented database and Spring Data MongoDB.
spring-boot-starter-jooq Used for jOOQ to access SQL databases. An alternative to spring-boot-starter-data-jpa or spring-boot-starter-jdbc.
spring-boot-starter-jta-narayana Used for Spring Boot Narayana JTA Starter.
spring-boot-starter-cloud-connectors It is used for Spring Cloud Connectors that simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku.
spring-boot-starter-jta-bitronix It is used for JTA transactions using Bitronix.
spring-boot-starter-social-twitter For Spring Social Twitter.
spring-boot-starter-data-rest For exposing Spring Data repositories over REST using Spring Data REST.

Spring Boot Technical Starters

Name Description
spring-boot-starter-undertow Used for Undertow as the embedded servlet container. An alternative to spring-boot-starter-tomcat.
spring-boot-starter-jetty Used for Jetty as the embedded servlet container. An alternative to spring-boot-starter-tomcat.
spring-boot-starter-logging Used for logging using Logback. Default logging starter.
spring-boot-starter-tomcat Used for Tomcat as the embedded servlet container. Default servlet container starter used by spring-boot-starter-web.
spring-boot-starter-log4j2 Used for Log4j2 for logging. An alternative to spring-boot-starter-logging.