Scenes
When the project back by the deployment of a change in the deployment after more than one address the session sharing problem most commonly used way is stored in the session redis such as cache. About session cookie and concepts will not repeat them here, in springboot-security environment, the session is stored in redis it is very, very simple to share, in addition to a few more configuration, almost no change any code. Sharing session to achieve the effect that, after the user logs in successfully on a single server above to access another one, the user is logged in. Create the following two different programs to configure session sharing.
Increased reliance
The session shared storage configuration in redis, you need to add two dependencies, one redis, the second is spring session:
Modify the configuration file
In the configuration file, redis need to configure some attributes of the data source and the session:
About session configuration, you can look according to ide tips:
You can see not only the session is stored in redis, it is also possible in a database or in MongoDB, but at the moment is to choose the most redis one way.
Add comment
Finally, add a comment in the class start @EnableRedisHttpSession:
test
First open the login page of a project, the login is successful,
Then open a browser, direct access to the home page of the second project, this time without logging direct access to:
Look redis stored in the session:
This realization of the session to share! In this case the one exit, the other will automatically exit, session data in redis will be automatically deleted.
Code Address: https://gitee.com/blueses/spring-boot-security 091 092