Auto-Wiring in Spring Beans
by, 07-07-2012 at 07:24 PM (1252 Views)
The relationship can be auto wired by the Spring container between collaborating beans. It will reuce the overhead of writing large XML configuration for big Spring based applications.
For dependency injection, following autowiring modes are used by the Spring container.
• no: This mode is the default mode and it means that no autowiring and explicit bean referencing should be used for wiring. For this wiring, you do not need to use anything special.
• byName: This is the autowiring by use of property name. The beans properties are looked by the Spring container for which autowire attribute is set in the configuration file. It will then match it and its properties will be wired with the same name bean in configuration file.
• byType: This is the autowiring by use of property type. The beans properties are looked by the Spring container in the configuration file and it matches and the exact type match property is wired. In case of more than one matching bean, a fatal error is generated by the Spring container.
• constructor: This autowiring is similar to byType autowiring but this autowiring is applied to the constructor arguments. A fatal error is generated in case of not finding exactly one bean of the argument type constructor.
To wire arrays and other collections, you can use constructor or byType autowiring.