From fd41f63ec065b890a539451532392fa9b5bb0b28 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 26 Dec 2016 10:57:50 +0100 Subject: [PATCH] Clarify programmatic contract (no annotation-driven injection) Issue: SPR-8704 --- .../beans/factory/FactoryBean.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java index ee7e60bdca7..1f45088ec91 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java @@ -17,31 +17,34 @@ package org.springframework.beans.factory; /** - * Interface to be implemented by objects used within a {@link BeanFactory} - * which are themselves factories. If a bean implements this interface, - * it is used as a factory for an object to expose, not directly as a bean - * instance that will be exposed itself. + * Interface to be implemented by objects used within a {@link BeanFactory} which + * are themselves factories for individual objects. If a bean implements this + * interface, it is used as a factory for an object to expose, not directly as a + * bean instance that will be exposed itself. * - *

NB: A bean that implements this interface cannot be used as a - * normal bean. A FactoryBean is defined in a bean style, but the - * object exposed for bean references ({@link #getObject()}) is always - * the object that it creates. + *

NB: A bean that implements this interface cannot be used as a normal bean. + * A FactoryBean is defined in a bean style, but the object exposed for bean + * references ({@link #getObject()}) is always the object that it creates. * - *

FactoryBeans can support singletons and prototypes, and can - * either create objects lazily on demand or eagerly on startup. - * The {@link SmartFactoryBean} interface allows for exposing - * more fine-grained behavioral metadata. + *

FactoryBeans can support singletons and prototypes, and can either create + * objects lazily on demand or eagerly on startup. The {@link SmartFactoryBean} + * interface allows for exposing more fine-grained behavioral metadata. * - *

This interface is heavily used within the framework itself, for - * example for the AOP {@link org.springframework.aop.framework.ProxyFactoryBean} - * or the {@link org.springframework.jndi.JndiObjectFactoryBean}. - * It can be used for application components as well; however, - * this is not common outside of infrastructure code. + *

This interface is heavily used within the framework itself, for example for + * the AOP {@link org.springframework.aop.framework.ProxyFactoryBean} or the + * {@link org.springframework.jndi.JndiObjectFactoryBean}. It can be used for + * custom components as well; however, this is only common for infrastructure code. * - *

NOTE: 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). + *

{@code FactoryBean} is a programmatic contract. Implementations are not + * supposed to rely on annotation-driven injection or other reflective facilities. + * {@link #getObjectType()} {@link #getObject()} invocations may arrive early in + * the bootstrap process, even ahead of any post-processor setup. If you need access + * other beans, implement {@link BeanFactoryAware} and obtain them programmatically. + * + *

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 Juergen Hoeller