• 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
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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: 14053
234
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.
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate 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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!