Spring Bean

https://medium.com/omarelgabrys-blog/spring-a-head-start-beans-configuration-part-2-4a8c239b070a

1. Spring Bean Scopes and Life Cycle - XML

Scopes

defines the scope of the bean object (singleton, prototype, etc). Spring supports five scopes, three of them are available only with the web apps.The default scope is “singleton”, while the “prototype” scope will create a new object every time we instantiate an object.

<bean id = "app" class = "App" scope="prototype"></bean>

With prototype scope, beans already are lazy instantiated. So, lazy instantiation is only useful when the scope is singleton.

Lifecycle of the bean is as the following:

Bean Instantiated -> Dependencies Injected -> Internal Processing -> Custom Init and destroy method(hooks) -> Bean is ready for use.

Last updated