Spring (and other ioc containers) offer different applications. One of the areas is singleton, i.e. The container creates an instance of the object only once and gives / introduces only one instance. Singleton is the default area, so most beans are really single point in terms of container, meaning they only have one instance.
However, there are other areas, such as prototype or request and session web pages.
When managing a bean, a container does the following:
- calls the
@PostConstruct and @PreDestroy methods (or the init and destroy methods configured by any available means) - introduces all its defined dependencies (= installs other beans existing in the container in the fields of this bean)
- creates AOP aspects around bean methods
Note. You can create multiple class objects that are defined as a singleton bean. A container creates an instance of an object only once, but your code is not limited to several instances.
Bozho source share