Spring Boot

When developing Spring Boot applications, you need to tell the Spring Framework where to look for Spring components. Using component scan is one method of asking Spring to detect Spring-managed components. Spring needs the information to locate and register all the Spring components with the application context when the application starts. What is Component Scanning…

Read More Component Scanning in a Spring Boot Application

In this tutorial, you will learn about @SpringBootTest annotation. It is this annotation that you will use to write Integration Tests for your Spring Boot application. @SpringBootTest annotation is used to create a Spring Application Context that will be used during the test. It will make Spring Framework start scanning classes of your application looking…

Read More @SpringBootTest Annotation Example

Starting from Spring Security version 5.7.0-M2 the WebSecurityConfigurerAdapter is deprecated. In this blog post you will find a complete code example that demonstrates how to configure HttpSecurity object to make it support User Authentication and User Authorization. Before Below is a code example that uses WebSecurityConfigurerAdapter. @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class WebSecurity extends WebSecurityConfigurerAdapter{…

Read More Migrating from Deprecated WebSecurityConfigurerAdapter

In this tutorial, you will learn to design and deploy the simple Spring Boot-based application to Docker. Overview Docker is becoming an increasingly important tool in the DevOps process.  It allows you to package an application, along with all its dependencies into a so-called container, and then run it in any environment. We will see…

Read More Deploying Spring Boot + MongoDB Application with Docker

In this tutorial, you will learn how to create a custom password encoder in a Spring Boot application that uses Spring Security. Table of contents Create a Spring Boot project and add database connection properties. Add a User model. Create a User repository. Implement a custom PasswordEncoder. Create a service class that implements UserDetailService Add…

Read More Custom Password Encoder in Spring Security

In this tutorial, the reader will learn how to deploy a Spring Boot REST app to Tomcat 10. According to Apache, the Jakarta EE platform is the evolution of the Java EE platform. Tomcat 10 and later implement specifications developed as part of Jakarta EE. Tomcat 9 and earlier implement specifications developed as part of…

Read More Deploy a Spring Boot REST App as a WAR to Tomcat 10

In this tutorial, you will learn how to start your Spring Boot application on a random port number. This 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 are interested to learn how to balance HTTP requests…

Read More Start Spring Boot App on a Random Port Number

In this tutorial, you will learn how to start your Spring Boot Web application on a different port number. By default, if no port number is configured, our Spring Boot Web application will start on port number 8080. To configure a different port number, you will need to update an application.properties file with the following…

Read More Start Spring Boot App on a Different Port Number

By default, Spring Boot RESTful Web service endpoints consume and produce JSON representation. But we can easily make our RESTful Spring Boot Web service endpoints consume and produce an XML representation of a resource as well. Add XML Support to Spring Boot Project To make our Spring Boot project consume and produce an XML representation…

Read More Consuming XML in Spring Boot REST

In this Spring Security tutorial, you will learn how to use the @PreAuthorize annotation to secure method invocation. You can use the @PreAuthorize annotation to secure either method in a Controller class or a method in a service layer class. There are other useful method level security annotations like the ones below. It is useful…

Read More Spring Security @PreAuthorize Annotation Example