How does Singleton work in Spring?

Spring The default value is Singleton for beans. Does this mean that when 100 users access the same site (service or bean), these 100 sessions share one instance of this bean service in streaming mode or 100 beans will be created and each session has its own bean. If this is the latter, then how does the Singleton template apply to it? Can anyone answer a possible code example with which we can see for ourselves.

+4
source share
2 answers

Singleton means that one instance will be created for this class for the lifetime of the application / process. Therefore, if 100 users access the same bean, they will all receive the same instance.

+6
source

This is the first. You get one object only with singleton. You can get one object per session, but this is another keyword that I consider.

0
source

All Articles