How to integrate Spring Security with Spring boot

Add the following dependency in your build.gradle


Basic Spring Security Configurations

  1. Add the dependency in your build.gradle

  2. Run your application gradle bootRun for gradle and mvn spring:run for maven


  1. The default username is user and the password will be printed in the logs as shown in the image above. So in this case you can login using
username = user
password = // printed in logs


A new password will be created each time the application restarts.

Spring Security Configurations with defined username and password

  1. Add the following in your
security.user.role=USER, ADMIN
  1. Using this approach you will be able to login to your application using the username and password defined by you.

  2. The default Roles assigned on login will be the one specified by you in properties file.

Also Read