|
From: Cameron B. <ca...@da...> - 2003-11-05 03:52:18
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> I have a FactoryBean that is a singleton. It is a prototype factory (is that correct terminoligy?)<br> <br> When the application context initialized, the FactoryBean.getObject() is being called before I call getBean() from my application.<br> <br> The problem is that the contract for BeanFactory.getObject() states that it shoud never be null.<br> <br> /**<br> * Return an instance (possibly shared or independent) of the object<br> * managed by this factory. As with a BeanFactory, this allows<br> * support for both the Singleton and Prototype design pattern.<br> * @return an instance of the bean <b>(should never be null)</b><br> * @throws Exception in case of creation errors<br> */<br> Object getObject() throws Exception;<br> <br> Though in my application, I can't gaurantee this. I am relying on source of information that doesn't exist until a servlet call is made.<br> <br> How come this happens, and is it necessary to create an instance that gets thrown away ?<br> <br> Cheers<br> <br> Cameron<br> <br> <br> <pre cols="72" class="moz-signature">-- Any damn fool can write code that a computer can understand... The trick is to write code that humans can understand. [Martin Fowler <a class="moz-txt-link-freetext" href="http://www.martinfowler.com/distributedComputing/refactoring.pdf">http://www.martinfowler.com/distributedComputing/refactoring.pdf</a>]</pre> </body> </html> |
|
From: Colin S. <col...@ex...> - 2003-11-05 04:20:11
|
This is happening because AbstractApplicationContext foreces singletons (which includes your FactoryBean) to be pre-instantiated. This essentially calls getBean() on the bean, which ends up calling getObject(). Coincidentally, just a few days ago I asked here why singletons were always preinstantiated, with no ability to turn off this behaviour, but nobody commented... It probably makes sense to be able to turn this off for specific beans. Regards, Colin Cameron Braid wrote: > I have a FactoryBean that is a singleton. It is a prototype factory > (is that correct terminoligy?) > > When the application context initialized, the FactoryBean.getObject() > is being called before I call getBean() from my application. > > The problem is that the contract for BeanFactory.getObject() states > that it shoud never be null. > > /** > * Return an instance (possibly shared or independent) of the object > * managed by this factory. As with a BeanFactory, this allows > * support for both the Singleton and Prototype design pattern. > * @return an instance of the bean *(should never be null)* > * @throws Exception in case of creation errors > */ > Object getObject() throws Exception; > > Though in my application, I can't gaurantee this. I am relying on > source of information that doesn't exist until a servlet call is made. > > How come this happens, and is it necessary to create an instance that > gets thrown away ? > > Cheers > > Cameron |
|
From: Cameron B. <ca...@da...> - 2003-11-05 04:29:02
|
Colin Sampaleanu wrote: > This is happening because AbstractApplicationContext foreces > singletons (which includes your FactoryBean) to be pre-instantiated. > This essentially calls getBean() on the bean, which ends up calling > getObject(). > > Coincidentally, just a few days ago I asked here why singletons were > always preinstantiated, with no ability to turn off this behaviour, > but nobody commented... It probably makes sense to be able to turn > this off for specific beans. > I agree. Wouldn't it make sense to not preinstantiate FactoryBeans that aren't singeltons (FactoryBean.isSingelton()=false) since this initial instance will be disposed of anyway. Thanks, Cameron. > Regards, > Colin > > Cameron Braid wrote: > >> I have a FactoryBean that is a singleton. It is a prototype factory >> (is that correct terminoligy?) >> >> When the application context initialized, the FactoryBean.getObject() >> is being called before I call getBean() from my application. >> >> The problem is that the contract for BeanFactory.getObject() states >> that it shoud never be null. >> >> /** >> * Return an instance (possibly shared or independent) of the object >> * managed by this factory. As with a BeanFactory, this allows >> * support for both the Singleton and Prototype design pattern. >> * @return an instance of the bean *(should never be null)* >> * @throws Exception in case of creation errors >> */ >> Object getObject() throws Exception; >> >> Though in my application, I can't gaurantee this. I am relying on >> source of information that doesn't exist until a servlet call is made. >> >> How come this happens, and is it necessary to create an instance that >> gets thrown away ? >> >> Cheers >> >> Cameron > > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > -- 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] |