|
From: Cameron B. <ca...@da...> - 2003-11-04 15:44:54
|
Great Explanation ! Thanks. It makes perfect sense now :) Cameron jürgen höller [werk3AT] wrote: >Effectively, FactoryBean.isSingleton just gives a hint whether getObject will return a cached singleton or a new instance on each call. Currently, this is just evaluated for getBeansOfType checks. The singleton flag of the bean definition on the other hand determines how the bean factory treats the FactoryBean itself. > >If the FactoryBean is not a singleton, each reference to it will create a new FactoryBean in the bean factory. That instance can in turn return an internally cached singleton on getObject or a new object on each call. Obviously, a non-singleton FactoryBean that returns a singleton object does not make much sense. > >So if you implement FactoryBean.isSingleton = false and correspondingly create a new instance on each getObject call to your FactoryBean, bean references will always get a new object. Making the FactoryBean itself a singleton too is orthogonal to this; you will almost always have it as singleton. > >So there are two independent singleton statuses involved: >- the one of the FactoryBean: Should the bean factory create a new FactoryBean on each reference? >- the one of the object created by the FactoryBean: Does the FactoryBean create a new object on each getObject call? > >Juergen > > >-----Original Message----- >From: spr...@li... >[mailto:spr...@li...]On Behalf >Of Cameron Braid >Sent: Tuesday, November 04, 2003 4:06 PM >To: spr...@li... >Subject: [[W3-SPAM]] - [Springframework-developer] Question about Bean >Factories - the Singleton attribute/property - Email found in subject > > >I am implementing a bean factory that is not a singleton. > >There are two places where I can specify this property : > >1) in the <bean singleton="true|false|"> tag >2) in the boolean FactoryBean.isSingleton() > >The doco states : > > The singleton status of the FactoryBean itself will > * generally be provided by the owning BeanFactory. > >Please explain how this works. > >If I implement isSingleton = false, then someone configures <bean ... >singleton="true" > what will happen ? > >Thanks, > >Cameron > > > -- Any damn fool can write code that a computer can understand... The trick is to write code that humans can understand. [Martin Fowler http://www.martinfowler.com/distributedComputing/refactoring.pdf] |