diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Bean.java b/spring-context/src/main/java/org/springframework/context/annotation/Bean.java index a2fd1e4de7..05943b8edc 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Bean.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Bean.java @@ -77,7 +77,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; *

Typically, {@code @Bean} methods are declared within {@code @Configuration} * classes. In this case, bean methods may reference other {@code @Bean} methods * in the same class by calling them directly. This ensures that references between - * beans are strongly typed and navigable. Such so-called 'inter-bean references' are + * beans are strongly typed and navigable. Such so-called 'inter-bean references' are * guaranteed to respect scoping and AOP semantics, just like getBean() lookups * would. These are the semantics known from the original 'Spring JavaConfig' project * which require CGLIB subclassing of each such configuration class at runtime. As a @@ -105,13 +105,21 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; * in a {@code @Component} class or even in a plain old class. In such cases, * a {@code @Bean} method will get processed in a so-called 'lite' mode. * - *

In contrast to the semantics for bean methods in {@code @Configuration} classes - * as described above, bean methods in lite mode will be called as plain - * factory methods from the container (similar to {@code factory-method} - * declarations in XML) but with prototype semantics. The containing + *

Bean methods in lite mode will be treated as plain factory + * methods by the container (similar to {@code factory-method} declarations + * in XML), with scoping and lifecycle callbacks properly applied. The containing * class remains unmodified in this case, and there are no unusual constraints for - * factory methods; however, scoping semantics are not respected as described - * above for 'inter-bean method' invocations in this mode. For example: + * the containing class or the factory methods. + * + *

In contrast to the semantics for bean methods in {@code @Configuration} classes, + * 'inter-bean references' are not supported in lite mode. Instead, + * when one {@code @Bean}-method invokes another {@code @Bean}-method in lite + * mode, the invocation is a standard Java method invocation; Spring does not intercept + * the invocation via a CGLIB proxy. This is analogous to inter-{@code @Transactional} + * method calls where in proxy mode, Spring does not intercept the invocation — + * Spring does so only in AspectJ mode. + * + *

For example: * *

  * @Component