• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Is not autowire a another type of dependendcy injection?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic