• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic