@@ -186,14 +186,37 @@ implementation type, consider declaring the most specific return type on your fa
186
186
method (at least as specific as required by the injection points referring to your bean).
187
187
====
188
188
189
+ .[[beans-autowired-annotation-self-injection]]Self Injection
190
+ ****
191
+ `@Autowired` also considers self references for injection (that is, references back to
192
+ the bean that is currently injected).
193
+
194
+ Note, however, that self injection is a fallback mechanism. Regular dependencies on other
195
+ components always have precedence. In that sense, self references do not participate in
196
+ regular autowiring candidate selection and are therefore in particular never primary. On
197
+ the contrary, they always end up as lowest precedence.
198
+
199
+ In practice, you should use self references as a last resort only – for example, for
200
+ calling other methods on the same instance through the bean's transactional proxy. As an
201
+ alternative, consider factoring out the affected methods to a separate delegate bean in
202
+ such a scenario.
203
+
204
+ Another alternative is to use `@Resource`, which may obtain a proxy back to the current
205
+ bean by its unique name.
206
+
207
+ ======
189
208
[NOTE]
190
209
====
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.
210
+ Trying to inject the results from `@Bean` methods in the same `@Configuration` class is
211
+ effectively a self-reference scenario as well. Either lazily resolve such references
212
+ in the method signature where it is actually needed (as opposed to an autowired field
213
+ in the configuration class) or declare the affected `@Bean` methods as `static`,
214
+ decoupling them from the containing configuration class instance and its lifecycle.
215
+ Otherwise, such beans are only considered in the fallback phase, with matching beans
216
+ on other configuration classes selected as primary candidates instead (if available).
196
217
====
218
+ ======
219
+ ****
197
220
198
221
You can also instruct Spring to provide all beans of a particular type from the
199
222
`ApplicationContext` by adding the `@Autowired` annotation to a field or method that
0 commit comments