Skip to content

Commit c4194ee

Browse files
jhoellerunknown
authored andcommitted
Added paragraph on BeanPostProcessor side effects when autowiring dependencies into it (SPR-9577)
1 parent 36b2e1f commit c4194ee

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/reference/docbook/beans-extension-points.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
/>.</para>
6666
</note>
6767

68-
<para>The
69-
<interfacename>org.springframework.beans.factory.config.BeanPostProcessor</interfacename>
68+
<para>The <interfacename>org.springframework.beans.factory.config.BeanPostProcessor</interfacename>
7069
interface consists of exactly two callback methods. When such a class is
7170
registered as a post-processor with the container, for each bean instance
7271
that is created by the container, the post-processor gets a callback from
@@ -93,8 +92,7 @@
9392
<note>
9493
<title>Programmatically registering <interfacename>BeanPostProcessors
9594
</interfacename></title>
96-
<para>
97-
While the recommended approach for <interfacename>BeanPostProcessor
95+
<para>While the recommended approach for <interfacename>BeanPostProcessor
9896
</interfacename> registration is through <interfacename>ApplicationContext
9997
</interfacename> auto-detection (as described above), it is also
10098
possible to register them <emphasis>programmatically</emphasis>
@@ -108,8 +106,7 @@
108106
registration</emphasis> that dictates the order of execution. Note also
109107
that <interfacename>BeanPostProcessors</interfacename> registered
110108
programmatically are always processed before those registered through
111-
auto-detection, regardless of any explicit ordering.
112-
</para>
109+
auto-detection, regardless of any explicit ordering.</para>
113110
</note>
114111

115112
<note>
@@ -135,6 +132,14 @@
135132
<quote><emphasis>Bean foo is not eligible for getting processed by all
136133
BeanPostProcessor interfaces (for example: not eligible for
137134
auto-proxying)</emphasis></quote>.</para>
135+
136+
<para>Note that if you have beans wired into your <interfacename>BeanPostProcessor</interfacename>
137+
using autowiring or <interfacename>@Resource</interfacename> (which may fall back to autowiring),
138+
Spring might access unexpected beans when searching for type-matching dependency candidates,
139+
and therefore make them ineligible for auto-proxying or other kinds of bean post-processing.
140+
For example, if you have a dependency annotated with <interfacename>@Resource</interfacename>
141+
where the field/setter name does not directly correspond to the declared name of a bean and
142+
no name attribute is used, then Spring will access other beans for matching them by type.</para>
138143
</note>
139144

140145
<para>The following examples show how to write, register, and use

0 commit comments

Comments
 (0)