Spring

Spring - Bean Definition

Spring - Bean Definition

The objects that structure the foundation of your application and that are overseen by the Spring IoC compartment are called beans. A bean is an item that is started up, gathered, and in any case oversaw by a Spring IoC container. These beans are made with the arrangement metadata that you supply to the compartment. For instance, XML <bean/> definitions you have effectively found in the past sections. Bean definition contains the data called setup metadata, which is required for the holder to know the accompanying − 

  • Step by step instructions to make a bean 
  • Bean's lifecycle subtleties 
  • Bean's conditions 

All the above setup metadata converts into many accompanying properties that make up each bean definition. 

Properties:

  • class 

This property is required and indicates the bean class to be utilized to make the bean. 

  • name 

This trait indicates the bean identifier exceptionally. In XML-based design metadata, you utilize the id and name credits to indicate the bean identifier(s). 

  • scope 

This quality indicates the extent of the items made from a specific bean definition, and it will be examined in the bean scopes part. 

  • constructor-arg 

This is utilized to infuse the conditions and will be examined in ensuing parts. 

  • properties 

This is utilized to infuse the conditions and will be talked about in the resulting sections. 

  • autowiring mode 

This is utilized to infuse the conditions and will be talked about in the resulting sections. 

  • lazy-initialization mode 

A lazy-initialization bean advises the IoC holder to make a bean case when it is first mentioned instead of the startup. 

  • initialization technique 

A callback is to be called soon after all essential properties on the bean have been set by the holder. It will be talked about in the bean life cycle section. 

  • annihilation strategy 

A callback is to be utilized when the compartment containing the bean is annihilated. It will be examined in the bean life cycle part. 

Spring Configuration Metadata 

Spring IoC holder is completely decoupled from the organization where this arrangement metadata is composed. Following are the three significant strategies to give setup metadata to the Spring Container − 

  • XML-based setup record. 
  • Explanation based setup 
  • Java-based setup