Thursday, 9 February 2017

Autowiring In Spring

It is possible to automatically let Spring framework resolve dependencies for the bean by inspecting contents of the BeanFactory. This is kown as Autowiring.  A BeanFactory is able to autowire relationships between collaborating beans.
The autowiring functionality has five modes. Autowiring is specified per bean and can thus be enabled for some beans, while other beans won't be autowired.
Using autowiring, it is possible to reduce or eliminate the need to specify properties or constructor arguments, saving a significant amount of typing. In an XmlBeanFactory, the autowire mode for a bean definition is specified by using the autowire attribute of the bean element.

Some advantages of autowiring:
  • It can reduce the volume of configuration required.
  • It can cause configuration to keep itself up to date as your objects evolve. For example, if you need to add an additional dependency to a class, that dependency can be satisfied automatically without the need to modify configuration.
Some disadvantages of autowiring:

  • Wiring information may not be available to tools that may generate documentation from a Spring application context.
  • Autowiring by type will only work when there is a single bean definition of the type specified by the setter method or constructor argument. You need to use explicit wiring if there is any potential ambiguity.
Autowiring In Spring
Autowiring In Spring

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...