Skip to content

Commit 28e114b

Browse files
committed
Clarify programmatic contract (no annotation-driven injection)
Issue: SPR-8704 (cherry picked from commit fd41f63)
1 parent 99226e0 commit 28e114b

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,31 +17,34 @@
1717
package org.springframework.beans.factory;
1818

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

0 commit comments

Comments
 (0)