MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

Spring Framework

Spring Projects

Spring Project 1

Autowire in Spring Framework
Previous Home Next

Introduction:An autowiring is the facility provided by framework to satisfied by dependency of manage bean without configuration information. It means that the autowiring solved problem to write very long configuration information.

Type of method to Autowire

The following four method are used by IOC container to autowire bean dependency.

  1. Autowire by Type
  2. Autowire by Name
  3. Autowire by Constructor
  4. Autowire by autodetect

Autowire by Type: In autowiring by type , The IOC container used the bean property by type to identified the beans to be injected i.e in order to used autowiring by type we need to simply configure one bean for each property of the target bean.

Note: Facility of autowiring are used only with object type dependency i.e primitive dependency are note autowire.

Syntax :

 <bean id="x" class="org.r4r.A"/>
<bean id="b" class="org.r4r.B" autowire="byType"/>


Disadvantage of Autowire
  1. Optional dependency are specified using by type because dependency are injected by setter method.
  2. Autowiring by type can not be used if there are more than one beans. Configured for a properties type.

Autowire by Name: In this case IOC container uses the name of a bean property to fined out the bean for injecting i.e in this approach the configuration bean to be used for satisfied the dependency of the bean must have the same as the bean property.


<bean id="a" class="org.r4r.A"/>
<bean id="y" class="org.r4r.A"/>
<bean id="b" class="org.r4r.B" autowire="byName"/>

Disadvantage of Autowire

  1. Only optional dependency can be autowire for this approach.
  2. This approach would work of a bean of different type is configure using the same name as the property of a bean which uses autowiring.

Autowire by Constructor: In this approach type of parameter of the constructor are used to identified the bean to be injected in case of overloaded constructed has a maximum parameter will choose. This approach is same as autowiring by type accept dependency are injected through constructor in it.


 <bean id="a" class="org.r4r.A"/>
<bean id="b" class="org.r4r.B" autowire="constructor"/>

Autowire by Autodetect:This approach is a combination of autowiring by constructor and autowiring by type in it dependency is injected using the type of property if target bean has a default constructor and dependency are injected using constructor injection if target bean has a parameterize constructor.

Note: This is the default strategy of the autowiring.


<bean id="x" class="org.r4r.A"/>
<bean id="b" class="org.r4r.B" autowire="autodetect"/>

Limitation of Autowiring: Major drawback of autowiring is understandability is loosed.

Previous Home Next