Skip to main content

Create Microservice and Register with Eureka Server Step By Step

 Step 1 : File -> New -> Spring Starter Project -> Add Configuration as below and Next :


Step 2 :  Add Dependencies and click Finish :



Step 3 : Edit properties file as :

	server.port=0
	spring.application.name=AccountService
	eureka.client.register-with-eureka=true
	eureka.client.fetch-registry=true
	eureka.client.serviceUrl.defaultZone=http://localhost:8001/eureka/
Step 4 : add @EnableDiscoveryClient annotation at main class :

	package com.crtr4u.www;
	
	import org.springframework.boot.SpringApplication;
	import org.springframework.boot.autoconfigure.SpringBootApplication;
	import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
	
	@SpringBootApplication
	@EnableDiscoveryClient
	public class AccounMicroserviceApplication {
	
		public static void main(String[] args) {
			SpringApplication.run(AccounMicroserviceApplication.class, args);
		}
	
	}

Step 5 : create a simple restcontroller as below :

package com.crtr4u.www;

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

@RestController
@RequestMapping("/account")
public class AccountController {
	@GetMapping("/check")
	public String status() {
		return "Account Service is Working";
	}
}

Step 6 : Now Run the microservice : Note - Your Eureka Server should be in running state :
check our article for Eureka Server on this link : Eureka Server Steps .
once Eureka Server Started successfully , then run this application : and refresh eureka server console ,
you will find your microservice registered on Eureka Console as below :


Happy Learning.