Service Registry is an Implementation of Service Discovery Pattern.
What is Service Discovery Pattern ?
Service Discovery Pattern is used to find the network location of micro services,service registry maintain global view of micro services network location.Different micro services register their details with Service Registry.Service Registry display status of all registered micro services.
1.Micro service register itself on Service Registry
2.client discover network path of micro service
3.client connect to micro service directly
Creating First Spring Boot Application Step By Step
Step 1: visit https://start.spring.io/
Step 2: select build tool , java version and add group name , package as in below example :
Spring Boot Sample Configuration Example :
Step 3: Click on Add Dependencies button on right side of screen :
It will open a search box , In search box type web as below :
Step 4: Select Spring Web From list , it will add Spring Web Dependency as below :
Step 5: Click on Generate Button , it will download maven project zip file automatically.
Step 6: Once zip file downloaded , extract it or unzip it and import in IDE .
Steps To import Spring Boot Maven Project In STS IDE
Step 1: Open STS and give path for workspace creation as below :
Step 2: Click On Launch Button , it will open your STS workspace as below :
Step 3: In Previous steps we have downloaded our project zip file from https://start.spring.io/ , i hope you extracted zip file , after extracting zip file , check your STS IDE , on left side we have option to Import Project , click on Import Projects(last option in left side window).
Step 4: when you click on Import Projects , it will display below window :
Step 5: Type Maven In above window and select Existing Maven Project option and click on Next as below :
Step 6: It will display below Window
Step 7: Click on browse and go to your extracted project, select path of pom.xml file from extracted project as below :
Step 8: click on Finish , it will import project in workspace and it will download all required dependencies automatically , if your internet speed is not good then it may take some time to download required dependencies /jars/
Step 9: Once imported successfully , expand project as given in below screen in left window , go to src/main/java location , go to your package and you will find one Java class with @SpringBootApplication annotation as below :
Step 10: You can right click and run this class as a Java Application or Spring Boot Application.
Step 11: Spring Boot add tomcat server automatically because of Spring Web Dependency which we added , if application run without any error you will get below result on console :
Our Application started successfully by default on port number 8080 of embedded tomcat server.
some important annotation which we will use in Upcoming Sessions
@SpringBootApplication : it is main annotation , indicate the execution starting class,and in this class main() method uses Spring Boots SpringApplication.run() method to launch an application, our execution start from same class. this annotation automatically add these 3 annotations :
1>@Configuration
2>@EnableAutoConfiguration
3>@ComponentScan
@RestController : Indicate that our methods in API will not return view but will return text , response body as response.
@Controller + @ResponseBody = @RestController
@RequestMapping : to define URL mapping for our methods and for Rest Controller.
Happy Learning