Skip to content

Commit 5e153e4

Browse files
committed
Revised section on custom BeanPostProcessors
Issue: SPR-17556
1 parent 16e9b83 commit 5e153e4

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,10 +3958,10 @@ integration interfaces.
39583958
=== Customizing Beans by Using a `BeanPostProcessor`
39593959

39603960
The `BeanPostProcessor` interface defines callback methods that you can implement to
3961-
provide your own (or override the container's default) instantiation logic,
3962-
dependency-resolution logic, and so forth. If you want to implement some custom logic
3963-
after the Spring container finishes instantiating, configuring, and initializing a bean,
3964-
you can plug in one or more `BeanPostProcessor` implementations.
3961+
provide your own (or override the container's default) instantiation logic, dependency
3962+
resolution logic, and so forth. If you want to implement some custom logic after the
3963+
Spring container finishes instantiating, configuring, and initializing a bean, you can
3964+
plug in one or more custom `BeanPostProcessor` implementations.
39653965

39663966
You can configure multiple `BeanPostProcessor` instances, and you can control the order
39673967
in which these `BeanPostProcessor` instances execute by setting the `order` property.
@@ -3975,13 +3975,13 @@ registration of `BeanPostProcessor` instances>>.
39753975

39763976
[NOTE]
39773977
====
3978-
`BeanPostProcessor` instances operate on bean (or object) instances. That is, the
3979-
Spring IoC container instantiates a bean instance and then `BeanPostProcessor` instances do
3980-
their work.
3978+
`BeanPostProcessor` instances operate on bean (or object) instances. That is,
3979+
the Spring IoC container instantiates a bean instance and then `BeanPostProcessor`
3980+
instances do their work.
39813981
39823982
`BeanPostProcessor` instances are scoped per-container. This is relevant only if you
3983-
use container hierarchies. If you define a `BeanPostProcessor` in one container, it
3984-
post-processes only the beans in that container. In other words, beans that are
3983+
use container hierarchies. If you define a `BeanPostProcessor` in one container,
3984+
it post-processes only the beans in that container. In other words, beans that are
39853985
defined in one container are not post-processed by a `BeanPostProcessor` defined in
39863986
another container, even if both containers are part of the same hierarchy.
39873987
@@ -3994,12 +3994,12 @@ The `org.springframework.beans.factory.config.BeanPostProcessor` interface consi
39943994
exactly two callback methods. When such a class is registered as a post-processor with
39953995
the container, for each bean instance that is created by the container, the
39963996
post-processor gets a callback from the container both before container
3997-
initialization methods (such as `InitializingBean.afterPropertiesSet()`, after any
3997+
initialization methods (such as `InitializingBean.afterPropertiesSet()` or any
39983998
declared `init` method) are called, and after any bean initialization callbacks.
39993999
The post-processor can take any action with the bean instance, including ignoring the
4000-
callback completely. A bean post-processor typically checks for callback interfaces, or it
4001-
may wrap a bean with a proxy. Some Spring AOP infrastructure classes are implemented as
4002-
bean post-processors in order to provide proxy-wrapping logic.
4000+
callback completely. A bean post-processor typically checks for callback interfaces,
4001+
or it may wrap a bean with a proxy. Some Spring AOP infrastructure classes are
4002+
implemented as bean post-processors in order to provide proxy-wrapping logic.
40034003

40044004
An `ApplicationContext` automatically detects any beans that are defined in the
40054005
configuration metadata that implements the `BeanPostProcessor` interface. The
@@ -4018,27 +4018,27 @@ initialization of other beans in the context, this early type detection is criti
40184018
[[beans-factory-programmatically-registering-beanpostprocessors]]
40194019
.Programmatically registering `BeanPostProcessor` instances
40204020
NOTE: While the recommended approach for `BeanPostProcessor` registration is through
4021-
`ApplicationContext` auto-detection (as described earlier), you can
4022-
register them programmatically against a `ConfigurableBeanFactory` by using the
4023-
`addBeanPostProcessor` method. This can be useful when you need to evaluate conditional
4024-
logic before registration or even for copying bean post processors across contexts in a
4025-
hierarchy. Note, however, that `BeanPostProcessor` instances added programmatically do not
4026-
respect the `Ordered` interface. Here, it is the order of registration that
4027-
dictates the order of execution. Note also that `BeanPostProcessor` instances registered
4028-
programmatically are always processed before those registered through auto-detection,
4029-
regardless of any explicit ordering.
4021+
`ApplicationContext` auto-detection (as described earlier), you can register them
4022+
programmatically against a `ConfigurableBeanFactory` by using the `addBeanPostProcessor`
4023+
method. This can be useful when you need to evaluate conditional logic before
4024+
registration or even for copying bean post processors across contexts in a hierarchy.
4025+
Note, however, that `BeanPostProcessor` instances added programmatically do not respect
4026+
the `Ordered` interface. Here, it is the order of registration that dictates the order
4027+
of execution. Note also that `BeanPostProcessor` instances registered programmatically
4028+
are always processed before those registered through auto-detection, regardless of any
4029+
explicit ordering.
40304030

40314031
.`BeanPostProcessor` instances and AOP auto-proxying
40324032
[NOTE]
40334033
====
40344034
Classes that implement the `BeanPostProcessor` interface are special and are treated
4035-
differently by the container. All `BeanPostProcessor` instances and beans that they directly reference
4036-
are instantiated on startup, as part of the special startup phase of the
4037-
`ApplicationContext`. Next, all `BeanPostProcessor` instances are registered in a sorted fashion
4038-
and applied to all further beans in the container. Because AOP auto-proxying is
4039-
implemented as a `BeanPostProcessor` itself, neither `BeanPostProcessor` instances nor the beans
4040-
they directly reference are eligible for auto-proxying and, thus, do not have aspects
4041-
woven into them.
4035+
differently by the container. All `BeanPostProcessor` instances and beans that they
4036+
directly reference are instantiated on startup, as part of the special startup phase
4037+
of the `ApplicationContext`. Next, all `BeanPostProcessor` instances are registere
4038+
in a sorted fashion and applied to all further beans in the container. Because AOP
4039+
auto-proxying is implemented as a `BeanPostProcessor` itself, neither `BeanPostProcessor`
4040+
instances nor the beans they directly reference are eligible for auto-proxying and,
4041+
thus, do not have aspects woven into them.
40424042
40434043
For any such bean, you should see an informational log message: `Bean someBean is not
40444044
eligible for getting processed by all BeanPostProcessor interfaces (for example: not

0 commit comments

Comments
 (0)