Commit ab7bec11 authored by Phillip Webb's avatar Phillip Webb

Update clarify of bean conditions

See gh-4104
parent ff0daa8d
...@@ -3880,20 +3880,15 @@ attribute to specify beans by type, or `name` to specify beans by name. The `sea ...@@ -3880,20 +3880,15 @@ attribute to specify beans by type, or `name` to specify beans by name. The `sea
attribute allows you to limit the `ApplicationContext` hierarchy that should be considered attribute allows you to limit the `ApplicationContext` hierarchy that should be considered
when searching for beans. when searching for beans.
Conditions are evaluated after all configuration classes have been processed. This clearly TIP: You need to be very careful about the order that bean definitions are added as these
means that you can't use it to make a whole configuration class conditional on the presence conditions are evaluated based on what has been processed so far. For this reason,
(or absence) of another bean. You can, however, use it when you have to share that we recommend only using `@ConditionalOnBean` and `@ConditionalOnMissingBean` annotations
condition with all the beans of that configuration class. on auto-configuration classes (since these are guaranteed to load after any user-define
beans definitions have been added).
[NOTE]
==== NOTE: `@ConditionalOnBean` and `@ConditionalOnMissingBean` do not prevent `@Configuration`
You also need to be very careful about ordering as the condition will be evaluated based on classes from being created. Using these conditions at the class level is equivalent to
the bean definitions that have been processed so far. Auto-configured `@Configuration` is marking each contained `@Bean` method with the annotation.
always parsed last (after any user defined beans) so it is recommended to restrict the use
of that condition on auto-configuration classes only. However, if you are sure that the bean
targeted at the condition won't be created by auto-configuration, then you could use it on a
normal configuration class with appropriate ordering.
====
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment