Clarify programmatic contract (no annotation-driven injection)

Issue: SPR-8704
This commit is contained in:
Juergen Hoeller 2016-12-26 10:57:50 +01:00
parent a77da869a6
commit fd41f63ec0
1 changed files with 24 additions and 21 deletions

View File

@ -17,31 +17,34 @@
package org.springframework.beans.factory; package org.springframework.beans.factory;
/** /**
* Interface to be implemented by objects used within a {@link BeanFactory} * Interface to be implemented by objects used within a {@link BeanFactory} which
* which are themselves factories. If a bean implements this interface, * are themselves factories for individual objects. If a bean implements this
* it is used as a factory for an object to expose, not directly as a bean * interface, it is used as a factory for an object to expose, not directly as a
* instance that will be exposed itself. * bean instance that will be exposed itself.
* *
* <p><b>NB: A bean that implements this interface cannot be used as a * <p><b>NB: A bean that implements this interface cannot be used as a normal bean.</b>
* normal bean.</b> A FactoryBean is defined in a bean style, but the * A FactoryBean is defined in a bean style, but the object exposed for bean
* object exposed for bean references ({@link #getObject()}) is always * references ({@link #getObject()}) is always the object that it creates.
* the object that it creates.
* *
* <p>FactoryBeans can support singletons and prototypes, and can * <p>FactoryBeans can support singletons and prototypes, and can either create
* either create objects lazily on demand or eagerly on startup. * objects lazily on demand or eagerly on startup. The {@link SmartFactoryBean}
* The {@link SmartFactoryBean} interface allows for exposing * interface allows for exposing more fine-grained behavioral metadata.
* more fine-grained behavioral metadata.
* *
* <p>This interface is heavily used within the framework itself, for * <p>This interface is heavily used within the framework itself, for example for
* example for the AOP {@link org.springframework.aop.framework.ProxyFactoryBean} * the AOP {@link org.springframework.aop.framework.ProxyFactoryBean} or the
* or the {@link org.springframework.jndi.JndiObjectFactoryBean}. * {@link org.springframework.jndi.JndiObjectFactoryBean}. It can be used for
* It can be used for application components as well; however, * custom components as well; however, this is only common for infrastructure code.
* this is not common outside of infrastructure code.
* *
* <p><b>NOTE:</b> FactoryBean objects participate in the containing * <p><b>{@code FactoryBean} is a programmatic contract. Implementations are not
* BeanFactory's synchronization of bean creation. There is usually no * supposed to rely on annotation-driven injection or other reflective facilities.</b>
* need for internal synchronization other than for purposes of lazy * {@link #getObjectType()} {@link #getObject()} invocations may arrive early in
* initialization within the FactoryBean itself (or the like). * the bootstrap process, even ahead of any post-processor setup. If you need access
* other beans, implement {@link BeanFactoryAware} and obtain them programmatically.
*
* <p>Finally, FactoryBean objects participate in the containing BeanFactory's
* synchronization of bean creation. There is usually no need for internal
* synchronization other than for purposes of lazy initialization within the
* FactoryBean itself (or the like).
* *
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller