Spring Autowiring

Autowiring Basics

Autowiring lets spring automatically satisfy bean dependency. 

Spring autowiring frees a programmar from the headache of explicitly wiring bean dependency.


Autowiring in spring is applicable on reference or objects only.

String and primitive values cannot be autowired.


Spring let's us autowire beans in any of the following ways:

  1. no → This is the default autowiring mode in Spring. Its use sends signal to container that no autowiring should be applied by default.
  2. byName → The byName autowiring mode wires the bean by matching the name of the bean and name of the property in java pojo class. For this mode to work bean name and property name in java must be same.
  3. byType → The byType autowiring mode wires the bean by matching the type of the bean and type of the property in java pojo class. 
  4. constructor
  5. autodetect  The autodetect autowiring mode is deprecated since Spring 3

We will learn in detail about each one of the above autowiring modes in upcoming sections of this spring tutorial.


Advantage of autowiring

  • It needs less configuration code to be written.

Dis-advantage of autowiring

  • Autowiring cannot be used for primitive values
  • Autowiring cannot be used for String values
  • May be difficult in debugging and troubleshooting.


Please Share this page
Views : 77
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!