Spring Boot Micro service — Part 1
Spring boot is full-stack application development framework. We can create Web based enterprise applications, Micro services and Standalone applications.
Spring boot framework is well known for creating production ready Micro services.
In this post , we will learn about how to create Spring boot project structure with Spring Initializr
Spring Initializr is a web based tool/project created by Pivotal which lets developers to create the structure of the Spring Boot Application.
It reduces developer’s time, so developer’s can concentrate on adding additional dependencies and writing code.
There are multiple ways to create Spring boot project structure.
Using Spring Initializr
Using Spring Tool Suite.
In this tutorial , we create project structure by using web based tool.
Go to https://start.spring.io/ and Choose
- Project type (Maven or Gradle)
- Spring Boot version,
- Packaging type (jar or War)
- Add required dependencies (Web , devtools, actuator etc)
Once we click on Generate button , tool will generate zip file and gets downloaded into our machine.
Extract the zip file and import the project into you favorite IDE (STS, Intellij), for this tutorial i m using intellij. Once you import project we will see this structure.
Below is the pom.xml file it contains various starter dependencies like spring-boot-starter-web, sprint-boot-starter-actuator.
As we included spring-boot-starter-web dependency it contains embedded tomcat server.
Next we will create application startup class.
Next we will create rest api with endpoint as /wish for that we need a controller class. This endpoint returns hello world message back to client.
Next will expose actuator endpoints, so that we can check heath status of our micro service. For this we need to include actuator starter dependency in pom.xml. Now we /actuator/info, /actuator/health and others gets available.
Now we do some logging and expose actuator endpoints , for this we do fallowing configuration in application.properties
Run this application as java application. It runs at default port number 8080. Now we test this /wish and /actuator/health endpoints.
Thanks for reading.