Answers

Question and Answer:

  Home  Sr.Java Web Developer

⟩ Do you know bean in Spring and List the different Scopes of Spring bean?

Beans are objects that form the backbone of a Spring application. They are managed by the Spring IoC container. In other words, a bean is an object that is instantiated, assembled, and managed by a Spring IoC container.

There are five Scopes defined in Spring beans.

☛ Singleton: Only one instance of the bean will be created for each container. This is the default scope for the spring beans. While using this scope, make sure spring bean doesn’t have shared instance variables otherwise it might lead to data inconsistency issues because it’s not thread-safe.

☛ Prototype: A new instance will be created every time the bean is requested.

☛ Request: This is same as prototype scope, however it’s meant to be used for web applications. A new instance of the bean will be created for each HTTP request.

☛ Session: A new bean will be created for each HTTP session by the container.

☛ Global-session: This is used to create global session beans for Portlet applications.

 132 views

More Questions for you: