Implementing the project
2.1 Entity
UserEntity.java (Entity class representing the model data) is explained below:
- This class acts as a simple java bean whose properties are returned as JSON response by the REST API’s get() method.
- ‘Lombok’ library is used to generate GETTER/SETTER methods automatically at runtime using ‘@Data‘ annotation.
- ‘@RequiredArgsConstructor‘ annotation is used to generate a zero-argument constructor and if final or ‘@NonNull’ fields are present, then respective arguments constructor is created.
- To add the ‘Lombok‘ library in your application, add the following dependency in your application’s project build.
- ‘@Component‘ annotation is used so that this bean automatically gets registered in Spring’s application context.
Java
package gfg; import lombok.Data; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @Component @Data @RequiredArgsConstructor public class UserEntity { String id = "1" ; String name = "Darshan.G.Pawar" ; String userName = "@drash" ; String email = "drash@geek" ; String pincode = "422-009" ; } |
2.2 Controller
RESTfulController.java (A REST API controller) for defining APIs and testing the program.
This controller’s get() method uses the UserEntity bean to return JSON response. UserEntiy bean is outsourced through ‘@Autowired‘ annotation which was registered in Spring’s application context.
Java
package gfg; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping ( "/get" ) public class RESTfulController { @Autowired UserEntity entity; @GetMapping ( "/data" ) public UserEntity getEntity(){ return entity; } } |
Spring Boot Actuator
Developing and Managing an application are the two most important aspects of the application’s life cycle. It is very crucial to know what’s going on beneath the application. Also when we push the application into production, managing it gradually becomes critically important. Therefore, it is always recommended to monitor the application both while at the development phase and at the production phase.
For the same use case, Spring Boot provides an actuator dependency that can be used to monitor and manage your Spring Boot application, By /actuator and /actuator/health endpoints you can achieve the purpose of monitoring.
- With the help of Spring Boot, we can achieve the above objectives.
- Spring Boot’s ‘Actuator’ dependency is used to monitor and manage the Spring web application.
- We can use it to monitor and manage the application with the help of HTTP endpoints or with the JMX.
Advantages of Actuator the Application
- It increases customer satisfaction.
- It reduces downtime.
- It boosts productivity.
- It improves Cybersecurity Management.
- It increases the conversion rate.
Contact Us