Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Spring Session works

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article was first published on the official account https://mp.weixin.qq.com/s/KCOFv0nRuymkX79-RZi9eg of Wechat, the Internet technology of vivo.

Author: Zhang Zhenglin

The HTTP protocol itself is stateless. In order to save the session information, the browser Cookie identifies the session request through SessionID, and the server stores the session information with SessionID as key. In single-instance applications, the storage of the application process itself can be considered. With the growth of the application volume, it is necessary to expand horizontally, and the problem of multi-instance session sharing follows.

Spring Session is to solve the problem of multi-process session sharing. This article will introduce how to use Spring Session and how Spring Session works.

1. Introduce the background

When the application is deployed in Tomcat, the session is maintained by Tomcat memory. If the application deploys multiple instances, the session cannot be shared. Spring Session is to solve the problem of session sharing in distributed scenarios.

2. Usage

Spring Session supports storage in Hazelcast, Redis, MongoDB, and relational databases. This article mainly discusses the storage of session in Redis.

Web.xml configuration:

SpringSessionRepositoryFilter org.springframework.web.filter.DelegatingFilterProxy springSessionRepositoryFilter / *

The main configuration of Spring:

PRV poolConfigRfex = "jedisPoolConfig" 3, workflow

Tomcat web.xml parsing steps:

ContextInitialized (ServletContextEvent arg0); / / Listenerinit (FilterConfig filterConfig); / / Filterinit (ServletConfig config); / / Servlet

Initialization order: Listener > Filter > Servlet.

1) load SessionRepositoryFilter into the Spring container through Tomcat's listener.

RedisHttpSessionConfiguration was declared in the Spring configuration file in the previous section, and SessionRepositoryFilter was generated in its parent class SpringHttpSessionConfiguration:

@ Beanpublic SessionRepositoryFilter

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report