What is Spring Beans?


What is Spring Beans?

Beans are the objects that make up the backbone of your application and are maintained by the Spring IoC container. A bean refers to a thing initiated by the Spring IoC container and assembled and managed by it. The configuration metadata you offer to the container is used to produce these beans.

Bean Inheritance:

Constructor arguments, property values, and container-specific information like initialization method, static factory method name, and so on may all be found in a bean definition.

The configuration definition of parent data is passed down to the definition of a child bean. The child definition has the ability to override or add values as needed.

Although Spring Bean's definition of inheritance differs from Java class inheritance, the inheritance notion is the same. A parent bean definition can be used as a template, and other child beans can inherit the appropriate configuration.

When using XML-based configuration metadata, the parent attribute is used to identify a child bean definition, with the parent bean as the value of this attribute.

Bean’s Scope:

You have the option of expressing a scope for a bean when defining the . For example, you can determine the bean's scope property prototype to force Spring to create a new bean instance each time one is required. Similarly, you should specify the bean's scope attribute to be singleton if you want Spring to return the same bean instance each time one is needed.