Spring Boot

In this tutorial, you will learn about @SpringBootTest annotation. You will use this annotation 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 scan your application classes and look for different annotations. Depending…

Read More @SpringBootTest Annotation Example

This tutorial will teach you how to migrate from the depricated WebSecurityConfigurerAdapter towards the content-based security configuration. Spring Security allowed customizing HTTP security by extending a WebSecurityConfigurerAdapter class. This customization included user authorization, user authentication, etc. But in Spring Security 5.7.0-M2 the WebSecurityConfigurerAdapter is deprecated. This is because Spring Framework developers encourage users to move…

Read More (Solved!) Deprecated WebSecurityConfigurerAdapter

To schedule a task in Spring Boot we use the @Scheduled annotation.  We place the @Scheduled annotation above the declaration of the method that should not expect any parameters, and the return type should be void.  Spring Boot internally uses the TaskScheduler interface to schedule the annotated execution methods. Schedule a task in Spring Boot – steps…

Read More How to Schedule a Task in Spring Boot

some data in a file import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.util.FileCopyUtils; import java.io.*; import java.nio.charset.StandardCharsets; @SpringBootApplication public class DemoApplication { public static void main(String[] args) throws IOException { SpringApplication.run(DemoApplication.class, args); readFile(); } public static void readFile() throws IOException { // read a file Resource resource = new ClassPathResource(“classpath:data.txt”); // get inputStream…

Read More Read a File From the Resources Folder in Spring Boot

In this tutorial, you will learn to design and run in a Docker container a simple Spring Boot application that uses MongoDB. To learn more about Docker, please check Docker Tutorials page. Overview Docker is becoming an increasingly important tool in the DevOps process.  It allows you to package an application, along with all its…

Read More Spring Boot Application with MongoDB in Docker Container

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

This tutorial demonstrates how to deploy a Spring Boot REST app to Tomcat 10. Apache states that the Jakarta EE platform represents the evolution of the Java EE platform. Tomcat 10 and later versions implement specifications that were developed as part of Jakarta EE. In contrast, Tomcat 9 and earlier versions implement specifications that were…

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

This tutorial will teach you how to start your Spring Boot Web application on a different port number. Read the following tutorial to learn how to start your Spring Boot application on a random port number. By default, if no port number is configured, our Spring Boot Web application will start on port number 8080.…

Read More Start Spring Boot Application on a Different Port Number

By default, Spring Boot RESTful web service endpoints consume and produce JSON representations. However, it’s possible to enable consuming XML and producing it for your REST API endpoints with minimal effort. This tutorial will guide you through the process of adding XML support to your Spring Boot application, allowing consuming XML and producing representations of…

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 to…

Read More Spring Security @PreAuthorize Annotation Example

In this Spring Boot tutorial, you will learn how to implement User Authentication(User Login) functionality for your RESTful Web Service application. There is also a step-by-step video demonstration on how to do User Authentication available here. The user authentication functionality we are going to implement in this tutorial will work the following way: A user…

Read More User Authentication – Spring Boot, Spring Security, JWT