This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Security 6.4.1!spring-doc.cn

Hello Spring Security

This section covers the minimum setup for how to use Spring Security with Spring Boot.spring-doc.cn

The completed application can be found in our samples repository. For your convenience, you can download a minimal Spring Boot + Spring Security application by clicking here.spring-doc.cn

Updating Dependencies

The only step you need to do is update the dependencies by using Maven or Gradle.spring-doc.cn

Starting Hello Spring Security Boot

You can now run the Spring Boot application by using the Maven Plugin’s run goal. The following example shows how to do so (and the beginning of the output from doing so):spring-doc.cn

Running Spring Boot Application
$ ./mvn spring-boot:run
...
INFO 23689 --- [  restartedMain] .s.s.UserDetailsServiceAutoConfiguration :

Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336

...

Spring Boot Auto Configuration

Spring Boot automatically:spring-doc.cn

  • Enables Spring Security’s default configuration, which creates a servlet Filter as a bean named springSecurityFilterChain. This bean is responsible for all the security (protecting the application URLs, validating submitted username and passwords, redirecting to the log in form, and so on) within your application.spring-doc.cn

  • Creates a UserDetailsService bean with a username of user and a randomly generated password that is logged to the console.spring-doc.cn

  • Registers the Filter with a bean named springSecurityFilterChain with the Servlet container for every request.spring-doc.cn

Spring Boot is not configuring much, but it does a lot. A summary of the features follows:spring-doc.cn