Life Cycle of Spring Beans

Beans Creation Scan the application to create beans Create beans and their dependencies Invoke init() Call initialization method (if configured) Defined in three different ways for different configurations Invoked once then bean and its dependencies are created Use beans in Application Using the beans in the application according to the requirements Invoke destroy() Call destroy …

Enable Spring Boot Devtools in IntelliJ

1. Add Dependency in pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> 2. In your intellij IDEA go to: file->settings->build,execution,deployment. Go to ->compiler->build project automatically. 3. Advanced Setting -> Enable auto-make

@RequestMapping, @GetMapping and @PostMapping in Spring

@RequestMapping Originally, Spring had only @RequestMapping annotation for mapping all the incoming HTTP request URLs to the corresponding controller methods. @RequestMapping(value = "/users", method = RequestMethod.GET) public Users getUsers() { } @RequestMapping(value = "/users", method = RequestMethod.POST) public User createUser(User user) { } @RequestMapping(value = "/users/{id}", method = RequestMethod.GET) public User getUser(@PathVariable("id") String id) { …

The Spring @Controller and @RestController Annotations

In Spring Boot, the controller class is responsible for processing incoming REST API requests, preparing a model, and returning the view to be rendered as a response. The controller classes in Spring are annotated either by the @Controller or the @RestController annotation. These mark controller classes as a request handler to allow Spring to recognize …