wood burning stoves*
The moose likes Spring and the fly likes Should not use getBean() method ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Should not use getBean() method ?" Watch "Should not use getBean() method ?" New topic
Author

Should not use getBean() method ?

Karnati Sudhakar
Ranch Hand

Joined: Aug 26, 2008
Posts: 270

I was going through the Spring 3.0 reference documentation and i found the following line:

You use getBean to retrieve instances of your beans. The ApplicationContext interface has a few other methods for retrieving beans, but ideally your application code should never use them. Indeed, your application code should have no calls to the getBean method at all, and thus no dependency on Spring APIs at all.


It is mentioned in the section 3.2.3 Using the container

So, If we dont use getBean() method at all,how can we get the beans into our code?

Thanks
Sudhakar
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Via autowiring. But they say "ideally".


[My Blog]
All roads lead to JavaRanch
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Via dependency injection/IoC (whether or not you're using autowiring).

Whether or not you'll have to use getBean depends on the app--if you're using a framework you might never make a call to getBean yourself--but the framework might. If you're using annotations, you might never even need to do that.
Karnati Sudhakar
Ranch Hand

Joined: Aug 26, 2008
Posts: 270

Thanks guys for your replies..

I think i need to dig more to understand what you guys are saying..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Should not use getBean() method ?