This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Why am I accessing the class that I shouldn't?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HelloSpringApp.java:

GymCoach.java:

And applicationContext.xml:


When executing above code (plus some basic interfaces and FortuneServices, probably doesn't matter), I get the following output:

Inside CRICKET-COACH no-arg constructor
Inside CRICKET-COACH setter method

Heavy weight bench presses
Not the best day it might be!



And here's the CricketCoach class:


So basically:
Inside HelloSpringApp I am creating theCoach object from a "myCoach" bean that's configured inside .xml.
myCoach bean is tied to GymCoach.

Yet for some reason, those "debugging sysouts" are printed as well. From CricketCoach. Why would my program access CricketCoach class? Once again, inside .xml myCoach is tied to GymCoach; not to CricketCoach.
 
Marshal
Posts: 14252
236
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has nothing to do with your myCoach bean. When Spring initialized, it creates all the beans you declared in your application context, so when lines 20-23 of your .xml file are processed, the CricketCoach constructor is invoked and the setFortuneService method is called to inject the service bean.
 
Nani Ksowy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, thanks.
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a 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!