Skip to content

Commit 5cd6543

Browse files
committed
Update @bean Javadoc re: 'lite' mode, scope, etc.
Updated the "@bean Lite Mode" section in order to properly document scoping and lifecycle semantics. Also fleshed out the discussion of the non-applicability of 'inter-bean references' in lite mode. Issue: SPR-9425
1 parent dc6b2ab commit 5cd6543

File tree

1 file changed

+15
-7
lines changed
  • spring-context/src/main/java/org/springframework/context/annotation

1 file changed

+15
-7
lines changed

spring-context/src/main/java/org/springframework/context/annotation/Bean.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
* <p>Typically, {@code @Bean} methods are declared within {@code @Configuration}
7878
* classes. In this case, bean methods may reference other {@code @Bean} methods
7979
* in the same class by calling them <i>directly</i>. This ensures that references between
80-
* beans are strongly typed and navigable. Such so-called 'inter-bean references' are
80+
* beans are strongly typed and navigable. Such so-called <em>'inter-bean references'</em> are
8181
* guaranteed to respect scoping and AOP semantics, just like <code>getBean()</code> lookups
8282
* would. These are the semantics known from the original 'Spring JavaConfig' project
8383
* which require CGLIB subclassing of each such configuration class at runtime. As a
@@ -105,13 +105,21 @@
105105
* in a {@code @Component} class or even in a <em>plain old class</em>. In such cases,
106106
* a {@code @Bean} method will get processed in a so-called <em>'lite'</em> mode.
107107
*
108-
* <p>In contrast to the semantics for bean methods in {@code @Configuration} classes
109-
* as described above, bean methods in <em>lite</em> mode will be called as plain
110-
* <em>factory methods</em> from the container (similar to {@code factory-method}
111-
* declarations in XML) but with <b><em>prototype</em></b> semantics. The containing
108+
* <p>Bean methods in <em>lite</em> mode will be treated as plain <em>factory
109+
* methods</em> by the container (similar to {@code factory-method} declarations
110+
* in XML), with scoping and lifecycle callbacks properly applied. The containing
112111
* class remains unmodified in this case, and there are no unusual constraints for
113-
* factory methods; however, scoping semantics are <b>not</b> respected as described
114-
* above for 'inter-bean method' invocations in this mode. For example:
112+
* the containing class or the factory methods.
113+
*
114+
* <p>In contrast to the semantics for bean methods in {@code @Configuration} classes,
115+
* <em>'inter-bean references'</em> are not supported in <em>lite</em> mode. Instead,
116+
* when one {@code @Bean}-method invokes another {@code @Bean}-method in <em>lite</em>
117+
* mode, the invocation is a standard Java method invocation; Spring does not intercept
118+
* the invocation via a CGLIB proxy. This is analogous to inter-{@code @Transactional}
119+
* method calls where in proxy mode, Spring does not intercept the invocation &mdash;
120+
* Spring does so only in AspectJ mode.
121+
*
122+
* <p>For example:
115123
*
116124
* <pre class="code">
117125
* &#064;Component

0 commit comments

Comments
 (0)