Skip to content

Commit 22b6d66

Browse files
committed
Document @order behavior on @configuration classes versus @bean methods
Includes brief note on self injection (extracted from qualifiers section). Closes gh-30177 Closes gh-28299
1 parent 9376e63 commit 22b6d66

File tree

1 file changed

+15
-0
lines changed
  • framework-docs/modules/ROOT/pages/core/beans/annotation-config

1 file changed

+15
-0
lines changed

Diff for: framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired.adoc

+15
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ implementation type, consider declaring the most specific return type on your fa
186186
method (at least as specific as required by the injection points referring to your bean).
187187
====
188188

189+
[NOTE]
190+
====
191+
As of 4.3, `@Autowired` also considers self references for injection (that is, references
192+
back to the bean that is currently injected). Note that self injection is a fallback.
193+
In practice, you should use self references as a last resort only (for example, for
194+
calling other methods on the same instance through the bean's transactional proxy).
195+
Consider factoring out the affected methods to a separate delegate bean in such a scenario.
196+
====
197+
189198
You can also instruct Spring to provide all beans of a particular type from the
190199
`ApplicationContext` by adding the `@Autowired` annotation to a field or method that
191200
expects an array of that type, as the following example shows:
@@ -268,6 +277,12 @@ use the same bean class). `@Order` values may influence priorities at injection
268277
but be aware that they do not influence singleton startup order, which is an
269278
orthogonal concern determined by dependency relationships and `@DependsOn` declarations.
270279
280+
Note that `@Order` annotations on configuration classes just influence the evaluation
281+
order within the overall set of configuration classes on startup. Such configuration-level
282+
order values do not affect the contained `@Bean` methods at all. For bean-level ordering,
283+
each `@Bean` method needs to have its own `@Order` annotation which applies within a
284+
set of multiple matches for the specific bean type (as returned by the factory method).
285+
271286
Note that the standard `jakarta.annotation.Priority` annotation is not available at the
272287
`@Bean` level, since it cannot be declared on methods. Its semantics can be modeled
273288
through `@Order` values in combination with `@Primary` on a single bean for each type.

0 commit comments

Comments
 (0)