This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "FactoryBean Watch "FactoryBean New topic

FactoryBean's isSingleton()

Arya Pramod

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,
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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

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

I am actually new to Spring Framework, so just getting some hands-on knowledge.
subject: FactoryBean's isSingleton()