my dog learned polymorphism*
The moose likes Other Application Frameworks and the fly likes FactoryBean's isSingleton() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "FactoryBean Watch "FactoryBean New topic
Author

FactoryBean's isSingleton()

Arya Pramod
Greenhorn

Joined: Jan 10, 2008
Posts: 12
Hi Everybody,

By returning true from isSingleton() method of FactoryBean implementation class,

Does Spring create a Singleton instance of the Class Implementing the FactoryBean Interface


If yes, then the following code



does not throw an exception even when the Implementing class has explicitly defined itself as a singleton through scope="prototype" and isSingleton() method returns true.

Thanks In Advance,
Pramod
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Returning true in isSingleton() will not magically make your bean a singleton. You have to make it work like a singleton, so you have to make sure that getObject() always returns the same object (a reference that can be cached). Is there any special reason why you are using this interface ?


[My Blog]
All roads lead to JavaRanch
Arya Pramod
Greenhorn

Joined: Jan 10, 2008
Posts: 12
Thank You Christophe,

I am actually new to Spring Framework, so just getting some hands-on knowledge.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: FactoryBean's isSingleton()