aspose file tools
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
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Reply 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: 17225
    
    1

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Is not autowire a another type of dependendcy injection?
 
Similar Threads
what is the meaning of "1=1" in sql statement
ejb-local-ref and ejb-ref
WA #1.....word association
Dependency Injection: Field injection and Setter Injection.
DI - Constructor injection / Setter Injection ?