Spring Framework

In this Spring Boot Security tutorial, you will learn how to use Spring method-level security to secure RestController methods with @PreAuthorize annotation. If you are interested in video lessons, then I also show how to create user Roles and Authorities and how to use Spring Method Level Security annotations in my video course: RESTful Web…

Read More Spring Method-Level Security with @PreAuthorize

This tutorial will teach you how to retrieve URI path variables in your Spring MVC web application. Define Path Variable To define a path variable in the URI path, we use curly brackets. For example, the @GetMapping annotation below specifies one path variable called userId, which is surrounded by curly brackets. @GetMapping(path=”/users/{userId}”) @PathVariable Annotation To…

Read More Spring MVC: Reading URI Path Variables

This tutorial will guide you on how to incorporate JUnit support into your Spring Boot application based on Maven. Spring Boot Starter Test Dependency To add JUnit and Mockito support to your Maven-based Spring Boot application, include the following dependencies in the <dependencies> section of your pom.xml file: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> By adding…

Read More JUnit Support in Spring Boot

In the software development process, testing is essential. There are two types of testing i.e. unit testing and integration testing. While unit testing focuses on testing the smallest component of an application, integration testing focuses on testing the end-to-end behavior of the application also known as endpoint testing. Integration testing verifies the @Controller and @RestController…

Read More Testing Spring Boot Applications with MockMvc

This tutorial will teach you how to use project Lombok in the Spring Boot application. Overview No doubt Java is a wonderful language, but one of the drawbacks of Java is its verbose nature. This makes it fairly complicated for everyday tasks such as composing a simple POJO object. For example, constructing of methods like Getters(), Setters(),…

Read More How to use Project Lombok in Spring Boot

This tutorial will teach you how to add Spring Security to your project and enable in-memory basic authentication. You will learn how to configure two different users with different Roles and Privileges. Both users’ roles and privileges will be stored in the memory of your Spring Boot application. If you use Spring Framework and OAuth,…

Read More Spring Security In-Memory Authentication

In this article, you will learn how to perform user authentication with Amazon Cognito in a Spring Boot application. But before we dive into that, let’s first explore what Amazon Cognito is. According to what’s mentioned on the AWS official website: Amazon Cognito lets you add user sign-up, sign-in, and access control to your web…

Read More User Authentication with Amazon Cognito in Spring Boot Application

Dependency injection is a design pattern in which a component’s dependencies are supplied externally rather than being hardcoded within the component itself. In Spring, developers mainly use 3 different types of dependency injection: constructor-based, setter-based, and field-based. In this tutorial, we will see how to use Setter-based Dependency Injection to inject a UsersRepository into a…

Read More Setter-based Dependency Injection in Spring

Spring is a popular Java-based framework for building applications. One of its core features is dependency injection, which is used to manage the relationships between objects and to make it easier to manage the dependencies in an application. In this tutorial, we will explore two of the main methods of dependency injection in Spring: constructor…

Read More Constructor vs Field Dependency Injection in Spring

This tutorial will teach you how to start your Spring Boot application on a random port number. Starting an application on a random port number is very helpful when you need to start multiple instances of the same Spring Boot application and then balance HTTP requests between the running instances. If you want to learn…

Read More Start Spring Boot App on a Random Port Number

In this article, we will learn about Many-to-Many relationships in JPA and how to implement them in a Spring Boot application. Let’s get started! @ManytoMany annotation A many-to-many relationship occurs when multiple records in one table are associated with multiple records in another table. The @ManyToMany annotation is used to define a many-valued association with…

Read More Many-to-Many Relationship in Spring Boot Rest with JPA

Dependency Injection is a design pattern that allows the separation of concerns in an application by removing the hard-coded dependencies between objects. In Dependency Injection, the objects are provided with their dependencies instead of having to hard-code them. This makes the application more flexible, maintainable, and easier to test. Spring Framework provides several ways to…

Read More Field-based Dependency Injection in Spring