wood burning stoves 2.0*
The moose likes Spring and the fly likes Is not autowire a another type of dependendcy injection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Is not autowire a another type of dependendcy injection?" Watch "Is not autowire a another type of dependendcy injection?" New topic
Author

Is not autowire a another type of dependendcy injection?

scott miles
Ranch Hand

Joined: Jun 16, 2011
Posts: 70
In most of the sites and books i have read two types os injection in spring that is

1)Constructor injection
2)Setter injection

As per my understanding autowiring is also a type of injection only. Is n't it? am i missing something here.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Autowiring is automatically doing your dependency injection for you through constructor or property/setter or even instance variable injection.

Autowiring just means that Spring will try to figure out what goes where, instead of you configuring all that yourself to tell Spring.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kevin Cho
Greenhorn

Joined: Nov 12, 2008
Posts: 20
scott miles wrote:In most of the sites and books i have read two types os injection in spring that is

1)Constructor injection
2)Setter injection

As per my understanding autowiring is also a type of injection only. Is n't it? am i missing something here.


No, you're right. You're thinking too low level on how Spring does DI. It does it either though XML and Annotations. In XML, yes you do it through constructor or setter. In Annotations, you use @Autowired or other similar tags to wire other spring beans. So even at Annotation level you're either injecting through constructor or setter. Yes, you can use Annotation on constructor.

In annotation @Autowired through setter is like
@Autowired
private A a;

through constructor is like
public B(@Autowired a){
this.a = a;
}

Hope this make sense.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is not autowire a another type of dependendcy injection?
 
Similar Threads
Dependency Injection: Field injection and Setter Injection.
ejb-local-ref and ejb-ref
WA #1.....word association
DI - Constructor injection / Setter Injection ?
what is the meaning of "1=1" in sql statement