From c4194ee1755e5f2a90df3839a5dc687aee10653f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 10 Feb 2013 23:03:36 +0100 Subject: [PATCH] Added paragraph on BeanPostProcessor side effects when autowiring dependencies into it (SPR-9577) --- .../docbook/beans-extension-points.xml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/reference/docbook/beans-extension-points.xml b/src/reference/docbook/beans-extension-points.xml index 551496d7be..d2a0aa80c3 100644 --- a/src/reference/docbook/beans-extension-points.xml +++ b/src/reference/docbook/beans-extension-points.xml @@ -65,8 +65,7 @@ />. - The - org.springframework.beans.factory.config.BeanPostProcessor + The org.springframework.beans.factory.config.BeanPostProcessor interface consists of exactly two callback methods. When such a class is registered as a post-processor with the container, for each bean instance that is created by the container, the post-processor gets a callback from @@ -93,8 +92,7 @@ Programmatically registering <interfacename>BeanPostProcessors </interfacename> - - While the recommended approach for BeanPostProcessor + While the recommended approach for BeanPostProcessor registration is through ApplicationContext auto-detection (as described above), it is also possible to register them programmatically @@ -108,8 +106,7 @@ registration that dictates the order of execution. Note also that BeanPostProcessors registered programmatically are always processed before those registered through - auto-detection, regardless of any explicit ordering. - + auto-detection, regardless of any explicit ordering. @@ -135,6 +132,14 @@ Bean foo is not eligible for getting processed by all BeanPostProcessor interfaces (for example: not eligible for auto-proxying). + + Note that if you have beans wired into your BeanPostProcessor + using autowiring or @Resource (which may fall back to autowiring), + Spring might access unexpected beans when searching for type-matching dependency candidates, + and therefore make them ineligible for auto-proxying or other kinds of bean post-processing. + For example, if you have a dependency annotated with @Resource + where the field/setter name does not directly correspond to the declared name of a bean and + no name attribute is used, then Spring will access other beans for matching them by type. The following examples show how to write, register, and use