File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring DI Vs Spring Autowiring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring DI Vs Spring Autowiring" Watch "Spring DI Vs Spring Autowiring" New topic

Spring DI Vs Spring Autowiring

Shiaber Shaam
Ranch Hand

Joined: Jun 16, 2006
Posts: 252
I am confusing between Spring DI and Autowiring. Could anyone please clarify these two terms and their types as of current version?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

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).

An IDE is no substitute for an Intelligent Developer.
Jackie Li
Ranch Hand

Joined: Sep 12, 2010
Posts: 30
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.
Ramy Nady
Ranch Hand

Joined: Feb 04, 2014
Posts: 94
Hello ,

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

Thanks in advance.

I agree. Here's the link:
subject: Spring DI Vs Spring Autowiring
It's not a secret anymore!