Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


Spring Autowiring


Spring container autowire relationship between different beans. Whenever we create a bean in Spring (In configuration file). Spring will check the dependency of that bean and inject the dependency @ run-time  Spring will identify @ run-time which bean to inject by different mechanism, It is called Autowiring.

Advantage of Autowiring
Reduce the development time by removing the necessity of specifying properties and constructor argument.
Enable Autowiring
XML Based Metadata Configuration
Autowiring can be enabled by using autowire attribute in element.

Annotation Based Metadata Configuration
Autowiring can be enabled by using @Autowire annotation

 
Autowiring Modes
Autowiring in spring has 5 different modes.

No                         :  No Autowiring will be done for given bean. ref element should be used to specify the bean to inject.
byName           :  Autowiring by Property Name
byType             :  Allows a property to be autowired if exactly one bean of the property type exists in the container.
constructor  :  Analogous to byType, but applies to constructor arguments.
 

Limitation of Autowiring
Explicit dependencies in property and constructor-arg settings always override autowiring.
Autowiring is less exact than explicit wiring.
Wiring information may not be available to tools that may generate documentation from a Spring container.
If no unique bean definition is available, an exception is thrown.
 

Disable Autowiring for a particular Bean
Use autowire-candidate and set it as FALSE.

asked Sep 1, 2015 in spring framework by rajesh
0 votes
31 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...