Is Spring a busy bean stored in an HttpSession?

Since I do not have deep knowledge about the implementation of the scope of spring. Can someone tell me if it is wise to use spring Session scoped beans, where the HttpSession object is very important. As a web application, where thousands of users access the site at the same time.

Is spring busy bean stored in HttpSession?

Or, even if the HttpSession object applies only to spring session bean coverage, aren't we making the session object heavy?

What does another form of storing any bean look like directly in the HttpSession object (which makes the HttpSession object a tough point of view)?

Thanks for the advanced.

+4
source share
3 answers

The object is not stored in an HTTP session. It is associated with a session identifier and is actually stored inside the Spring context. The session listener is used to clean up instances after the session is closed. See SessionScope JavaDoc.

+3
source

Here's what Spring says:

Defines one bean definition for the HTTP session life cycle. Valid only in the context of the Spring ApplicationContext web application.

"Heavy"? No harder than the object you put into it. Sessions must have a finite life. A few kbytes per session will not be at the end of your application. A simple calculation of the number of simultaneous sessions and object memory requirements should assure you of the memory settings of your application server. If necessary, you can always increase the minimum and maximum memory.

Saving things in an HTTP session is the same regardless of whether you are a Spring bean or not. The bean factory simply takes some extra steps to help you manage the object's life cycle.

+1
source

Is spring bean scope supported in an HttpSession object?

If the HttpSession object that you mentioned here is actually provided by spring-session (spring-session wraps the httpSession object in the original httpRequest), the response will be YES - indeed, the entire spring beans session is stored in the httpSession provided by spring-session as attributes.

Or even if the HttpSession object applies only to spring session bean coverage, aren't we making the session object heavy?

Not. The severity of httpSession is very dependent on the objects you insert. In addition, the beans session must be ephemeral. Last but not least, a session object in the microservices world is usually uploaded to a standalone store, such as Redis or HazelCast. Thus, it will not be considered "heavy" in terms of memory consumption.

How is this another form storing any bean directly in an HttpSession object (which makes the HttpSession object a heavy point of view)?

No difference whatsoever (assuming you are using spring change), since all spring beans sessions are stored in the httpSession file provided by spring-session as attributes.

0
source

Source: https://habr.com/ru/post/1396071/


All Articles