• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How does this works

 
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm learning a bit on Spring , so i didn't understand how this Execution happens because my A class object is depend on B class object , b instance is again depend on a ;




My beans.xml







My Manger Class



Can some one explain me , how DI happens here (Dependency Injection).
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, I recommend learning the latest version of Spring. The sample code you use BeanFactory instead of ApplicationContext. This means that you are using at least 5 year old material, as today to start up Spring you should create an ApplicationContext instead.

Now, in your case you changed your dependency to be property dependency. When you had constructor dependency, those dependencies are mandatory, but how can you create one before the other if they depend on each other both via constructor args. Just think in Java can you do

A a = new A(b);
B b = new B(a);

No because the first line doesn't work, there is no instance of B created yet, and if you tried to reverse the two lines, same problem but the other way.

But I can do

A a = new A();
B b = new B();
a.setB(b);
b.setA(a);

That works.

Now, I would take that circular dependency and see it as a code smell and refactor the code so that there is no circular dependency.

Hope that helps

Mark
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep! That Helps

Thank You
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic