This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Auto wiring in Spring with out bean tag

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks a lot Sir...
 
Hug your destiny! And hug this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!