Spring Boot

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 WebSecurityConfigurerAdapter is Deprecated. (Solved!)

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @EnableScheduling @SpringBootApplication public class ScheduledDemoApplication { public static void main(String[] args) { SpringApplication.run(ScheduledDemoApplication.class, args); } } import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class ScheduledTaskService { @Scheduled(fixedRate = 5000) public void execute() { // some logic that will be executed on a schedule System.out.println(“Code is being executed…”); } } Output:…

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