Create Application in Spring Boot MicroService
November 14, 2019 | Spring boot complete tutorial with example | No Comments
We know that in Monolithic application complete Code is at one place, in MicroService we divide this big monolithic application in small small microservices.
Suppose we create a separate application named EurekaClient-1 with some rest end points and host this application on Eureka Server so we don’t need to worry about details of this application.
To create this separate client application names EurekaClient-1 we have to follow below steps:
1- Add below dependency in your pom.xml file
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
2- Enable Eureka client using @EnableEurekaClient in your main class.
@EnableEurekaClient @SpringBootApplication public class EurekaClient1Application { public static void main(String[] args) { SpringApplication.run(EurekaClient1Application.class, args); } }
3- Give this application name, and a Port on which it will run, and path of the Eureka Server.
spring.application.name=client1 server.port=8081 eureka.client.service-url.default-zone=http://localhost:8761/eureka
4- Create Controller Class and make some end points.
@RestController public class ClientController1 { @GetMapping("/client1") public String client1() { return "I am client 1"; } }
Run your application and see your eureka server you will see your application hosted there.
Note: Before running your application make sure your eureka server is running.
Now access below url for getting your end point response