![]() |
VOOZH | about |
Eureka is a Service Registry provided by Netflix that helps microservices register and discover each other dynamically. Spring Boot and Eureka together make it easier to build scalable and distributed microservices applications.
Below are the steps for both Eureka Server and Eureka Client to start with Spring Boot and Eureka Service Registry.
Create a Spring Boot project using Spring Initializr.
After creating the Spring project, the file structure resembles the image below.
Open the application.properties file and put the below code for the server port and eureka server configuration to the project.
spring.application.name=eureka-server-config
server.port=9099
eureka.instance.prefer-ip-address=true
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
eureka.client.service-url.defaultZone=http://localhost:9099/eureka
In the main class, add the annotation @EnableEurekaServer to enable Eureka server functionality.
Run the application as a Spring Boot application and it runs successful then it starts at port 9099.
Add Dependencies:
After creating the Spring project, the file structure resembles the image below.
Open the application.properties file and put the below code for the server port and eureka client configuration to the project.
spring.application.name=user-service
server.port=8086
eureka.instance.prefer-ip-address=true
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
eureka.client.service-url.defaultZone=http://localhost:9099/eureka
Create the new Java class and it named as UserController. Go to src > org.example.userservice > UserController and put the below code.
Open the main class and add the @EnableDiscoveryClient into it.
Run the client application as a Spring Boot application and it runs successful then it starts at port 8086.
This dashboard provides the visibility into the microservices registered with Eureka Server and their status and the other relevant information.
If we follow the above steps, we can successfully implement the Eureka Service Registry of the spring boot application. By the following these steps and principles, we can effectively build and manage the Microservices Architecture using the Spring Boot and Eureka Service Registry.