|
From: Colin S. <col...@ex...> - 2004-07-31 14:26:01
|
Colin Sampaleanu wrote: > Colin Sampaleanu wrote: > >> Rob Harrop wrote: >> >>> Reading through the 1.1 docs it says that a parent bean can never >>> be accessed directly in an app either through <ref> or getBean() yet >>> I was able to do both. Is this an error in the doc or the code? >>> >>> Rob >> >> >> >> This is prefaced with the text 'In the case that the parent >> definition does not specify a class' before the sample... >> >> If it has a class, it's usable as its own bean, and in fact you need >> to make it lazy-init=true or singleton=true to stop the factory from >> pre-instantiating it. I need to update the docs to specifically >> mention that. > > > We could consider an 'abstract' attribute actually, to stop a bean > from ever being instantiated... I've clarified the text a bit in the manual: """ In the case that the parent definition does not specify a class: ... a sample here with no class set the parent bean can not get instantiated on its own; it's just a pure template or abstract bean definition that serves as parent definition for children. Trying to use such parent beans on it's own (by referring to it as a ref property of another bean, or doing an explicit getBean() call with the parent bean id, will result in an error. Similarly, the container's internal /preInstantiateSingletons/ method will completely ignore bean definitions which don't have either a parent or class attribute set, since they are not complete. /Important Note/: there is no way to explicitly declare a bean definition as abstract. As described above, if the definition does not have a class specified, then it is effectively be considered abstract, will not be pre-instantiated, and can not be instantiated at all (by the user). If the bean does have a class definition, then it can be instantiated. As well, XmlBeanFactory will by default pre-instantiate all singletons; so it is important that if you have a (parent) bean definition to be used only as a template, which specifies its class, and do not want the container to pre-instantiate it, you must make sure to set the /lazy-init/ attribute to /true/. """ Colin |