Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Auto wiring in Spring with out bean tag

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Team,

I'm new to the Spring Frame work,I have a ServiceImpl class and Though I'm not defining <Bean> Property properties in the context.xml the auto wiring is working to look up the dependency objects of the ServiceImpl class.Let me explain using an example,The below Dependency Injection is happening even I'm not mapping the Dao reference to the bean.Please share your thoughts

1)


context.xml
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, component-scan element configures Spring to scan all classes under specified package and autodiscover beans. That's how it's able to find your DAO.
You don't need a <bean> tag for the service bean either; it too will be autodiscovered.
Read about component scanning here.

Second, default behaviour of autowiring is to match by type. Your setTrackingDao setter method tells Spring to use setter based dependency injection. It checks the type of the member, sees that it's a TrackingDao, finds the TrackingDao class as part of component scanning, creates an instance of it, and injects it into your service bean.
Read about setter based DI here.

Important: From now on, when posting in CodeRanch, ensure that you enclose all code snippets in your question inside Code Tags for improved readability. See https://coderanch.com/t/659781/Wiki/Code-Tags for instructions. I'll edit your post and do it for you this time.

 
venkata Silla
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Sir...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic