Introduction: Spring @RequestParam annotation can be used to extract the query parameters in a handler method. In this quick tutorial, we’ll learn its usage. @RequestParam Annotation: Let’s first expose an API which returns a list of users with a given first nameĀ and age: @RestController public class UserController { … @GetMapping("/users") public List<User> getUsers(@RequestParam String firstName, […]
Introduction: Spring @Primary annotation is used to give a higher preference to the marked bean when multiple beans of the same type exist. Spring, by default, auto-wires by type. And so, when Spring attempts to autowire and there are multiple beans of the same type, we’ll get a NoUniqueBeanDefinitionException: Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException : No qualifying […]
Introduction: The Spring framework, by default, loads and eagerly initializes all beans at the application startup itself. In our application, we might have some pretty resource-intensive beans. We’ll prefer to load such beans on a need basis. We can achieve this using the Spring @Lazy annotation. In this tutorial, we’ll learn how to use @Lazy […]
Introduction: The Spring @Order annotation was first introduced in Spring 2.0. It was then used only to define the order among the AspectJ advices. Later in Spring 4.0, the implementation of this annotation was further improved a bit. Since then, it also supports ordering of Spring components or beans in a collection like a Java […]
Introduction: REST stands for Representational State Transfer and is an architectural guideline for API design. We assume that you already have a background in building RESTful APIs. In this tutorial, we’ll design a simple Spring Boot RESTful web application, exposing a few REST endpoints. Project Setup: Let’s start by downloading the project template via Spring […]
Introduction: In this quick tutorial, we’ll bootstrap a simple Spring Boot application backed by an in-memory H2 database. We’ll use the Spring Data JPA to interact with our database. Project Setup: Firstly, let’s generate our project template using Spring Initializr: On clicking the ‘Generate the project’ link, our project files will get downloaded. Now, if […]
Introduction: @SpringBootConfiguration annotation in Spring Boot is a class-level annotation which indicates that this class provides the application configuration. Generally, the class with the main() method is best-suited for this annotation. We usually use @SpringBootApplication annotation which automatically inherits the @SpringBootConfiguration annotation. Annotation Usage: When we mark a class with @SpringBootConfiguration, it means that the […]
Introduction: In this quick tutorial, we’ll explore the two very popular interfaces in Spring Boot: CommandLineRunner and ApplicationRunner. One common use case of these interfaces is to load some static data at application startup. Though, I have seen such usages mostly for test data setup only. Both of them are functional interfaces with a run() […]
Introduction: In this tutorial, we’ll take a look at Spring Boot and see how it’s different from the Spring framework. We’ll also discuss various features offered by Spring Boot. What is the Spring Boot? Spring is a powerful framework when it comes to developing enterprise-level applications. It provides us with features like dependency injection along […]
Introduction: Spring core container instantiates beans and manages their life-cycle. While defining a bean, we can provide its scope. Unless explicitly provided, singleton is the default scope of beans in a Spring container. We have five types of bean scopes available in Spring. In this tutorial, we’ll explore each of them. 1. singleton: The singleton […]