aspose file tools*
The moose likes Spring and the fly likes How does this works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How does this works" Watch "How does this works" New topic
Author

How does this works

Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

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).
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

Yep! That Helps

Thank You
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does this works