Introduction to bean scopes in Spring
In Chapter 3, Dependency Injection with Google Guice, we learned about different Spring modules along with dependency injection. In Spring, beans are the backbone of an application, and they are managed by a Spring IOC container. A bean is a class or object that is created using the configuration of metadata that we can pass to an IOC container. Before learning about scope, let's define a bean in Spring.
Bean definition
The metadata of a bean has its own properties with independent bean definitions. Some of these bean definitions are as follows:
- Class: This will be used to create a bean, and it is mandatory to mention a class name for which we are supposed to create a bean.
- Name: If we want to define different aliases for the bean, then we use the
name
attribute, with the help of a separator, such as a comma (,
) or semicolon (;
). When we have XML-based configuration, we can use thename
and/orid
attribute as an identifier for a bean. A bean with anid
attribute...