Hello Java developers! If you are developing Spring boot-based applications, Spring Security is the de facto standard for securing your Spring-based applications.
In this short tutorial, we'll be looking at building a basic login form using Spring Boot, Spring Security, and Thymeleaf.
First, let's briefly cover some project files that are of less interest:
*Application.java*
contains our main method and the @SpringBootApplication
annotation. The
standard way to start a spring boot application.src/main/resources/static/css/
to make the demo prettysrc/main/resources/
for demo purposes also*application.properties*
file is located under src/main/resources
where we can pass configuration parameters to our spring boot application. A complete list of configuration options can be found hereAs with all Spring boot applications, there are many 'Starter' libraries that make it easy to add jars to your classpath:
spring-boot-starter-parent
— brings in all the required spring dependencies and manages their
versionsspring-boot-starter-thymeleaf
— adds thymeleaf-spring5 and thymeleaf-extras-java8time
dependencies (more on thymeleaf)spring-boot-starter-security
— adds spring-security-config, spring-security-web, and spring-aop
dependenciesspring-boot-starter-test
— adds spring-boot-test, junit, hamcrest
and mockitospring-security-test
— adds the ability to mock user and user roles