This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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...
 
Tell me how it all turns out. Here is a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic