diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanFactoryPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanFactoryPostProcessor.java index c61ce8272d5647a43d83c82bb61b5de3a87d39cb..1619505c1f521a55e55606a9089935d9361313c2 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanFactoryPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanFactoryPostProcessor.java @@ -31,6 +31,12 @@ import org.springframework.beans.BeansException; *

See PropertyResourceConfigurer and its concrete implementations * for out-of-the-box solutions that address such configuration needs. * + *

A BeanFactoryPostProcessor may interact with and modify bean + * definitions, but never bean instances. Doing so may cause premature bean + * instantiation, violating the container and causing unintended side-effects. + * If bean instance interaction is required, consider implementing + * {@link BeanPostProcessor} instead. + * * @author Juergen Hoeller * @since 06.07.2003 * @see BeanPostProcessor diff --git a/spring-framework-reference/src/beans.xml b/spring-framework-reference/src/beans.xml index f6669f8378b99cbb7251d000d96a0709ab8bd74a..dabb662d2efc8d3bc559f4f5f5395cd281919c6a 100644 --- a/spring-framework-reference/src/beans.xml +++ b/spring-framework-reference/src/beans.xml @@ -4149,7 +4149,13 @@ org.springframework.scripting.groovy.GroovyMessenger@272961 instances (the objects that are created from the configuration metadata), then you instead need to use a BeanPostProcessor (described above in - . + . While it is technically + possible to work with bean instances within a + BeanFactoryPostProcessor (e.g. using + BeanFactory.getBean()), doing so causes + premature bean instantiation, violating the usual containter lifecycle. + This may cause negative side effects such as bypassing bean post + processing. Also, BeanFactoryPostProcessors are scoped per-container. This is only relevant if you are