• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring DI Vs Spring Autowiring

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confusing between Spring DI and Autowiring. Could anyone please clarify these two terms and their types as of current version?
 
Saloon Keeper
Posts: 27811
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you mean "Dependency Injection" when you say "DI".

Autowiring refers to the ability for Spring to find a bean and inject (using DI) it into the property of another bean based on its name. For example, if I have a bean named "dbConnection" and I have autowiring in effect for a bean named "PaycheckDAO" which supports dependency injection by providing a property setter named "setDbConnection", Spring will automatically inject dbConnection by calling setDbConnection automatically when it constructs the PaycheckDAO.

Without Autowiring, you'd have to explicitly tell Spring if you wanted this dependency injection - typically by coding a property reference in the bean configuration for the PaycheckDAO bean. Unlike Autowiring, the explicit property injection doesn't assume/require that the name of the property and the injected bean names have to match.

Autowiring is very powerful and very dangerous. Powerful, because it can really cut down on how much configuration you have to code, dangerous because since the configuration isn't explicitly coded, it isn't obvious what's being done. People can get into some serious arguments pro/con autowiring. For myself, I generally prefer explicit (manual) wiring, but I do have certain cases where it's advantageous to just let it autowire.

These capabilities date pretty far back into Spring's history, so the changes between releases are fairly minor. The major difference is that more recent versions of Spring support an @Autowire property annotation so that you don't have to code autowiring into the Spring configuration file(s).
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think both are DI. However, traditional way of configuration is by xml, autowiring is something new using annotation.

It's autowiringable by name, by type, and some other ways. However, as far as I know, annotation is necessary for that.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ,

Can you please clarify in details what is the difference between auto wiring and explicit (manual) wiring - with samples.

Thanks in advance.
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic