Microservice – Find Book Service using Spring Boot

What you will learn here about Microservices

  • Microservice – Find Book Service using Spring Boot


1)Please Start Naming server Before starting the Find Book service. Please visit following link for knowing how to implement naming server in microservice

Eureka naming server in microservices

2)Please Start Book Exchange service Before starting the Find Book service. Please visit following link for Book exchange service

Microservice – Book Exchange Service using Spring Boot

Please click on following link to download Find Book Service project.

Download Find Book Service project (681 downloads)

Microservice – Find Book Service using Spring Boot

Please follow the following steps to know to how to consume simple microservice using openfeign.
1)First create a simple maven project

2)Add following dependency in pom.xml which is shown below

Spring boot starter dependency


Spring boot open feign dependency


Eureka client discovery dependency


Dev tools dependency


open feign dependency

3)Please adding following configurations in application.properties of find book service which is shown below



naming server configuration in properties file

4)Please use @EnableFeignClients annotation to enable openfeign clients which is shown below

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

public class FindBookServiceApplication {

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


enable feign clients spring boot

5)Now please create Book entity which is shown below

import org.springframework.stereotype.Component;

public class Book {

	private int id;
	private String book_Name;
	private String author;
	private String description;
	private double price;
	private String environment;
	public double getPrice() {
		return price;
	public void setPrice(double price) {
		this.price = price;
	public String getEnvironment() {
		return environment;
	public void setEnvironment(String string) {
		this.environment = string;
	public int getId() {
		return id;
	public void setId(int id) {
		this.id = id;
	public String getBook_Name() {
		return book_Name;
	public void setBook_Name(String book_Name) {
		this.book_Name = book_Name;
	public String getAuthor() {
		return author;
	public void setAuthor(String author) {
		this.author = author;
	public String getDescription() {
		return description;
	public void setDescription(String description) {
		this.description = description;

book entity

6)Now please create feign client to consume another microservice using openfeign client which is shown below

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(name = "exchange-service", url="localhost:8000")
public interface ProxyService {
	public Book getBook(@PathVariable int id);


feign client spring boot

7)Now please create rest controller to get data from feign client which is shown below

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

public class FindBookController {
	ProxyService proxy;
	public Book getBook(@PathVariable int id) {
		return proxy.getBook(id);


feign client rest controller

8)Now please run the find book service

9)Now please go to browser and visit URL http://localhost:8100/book/id/1001 which is shown below
consume microservice using feign

You may also like...