@@ -384,6 +384,16 @@ supports this registration through the methods `registerSingleton(..)` and
384
384
`registerBeanDefinition(..)`. However, typical applications work solely with beans
385
385
defined through metadata bean definitions.
386
386
387
+ [NOTE]
388
+ ====
389
+ Bean metadata and manually supplied singleton instances need to be registered as early
390
+ as possible, in order for the container to properly reason about them during autowiring
391
+ and other introspection steps. While overriding of existing metadata and existing
392
+ singleton instances is supported to some degree, the registration of new beans at
393
+ runtime (concurrently with live access to factory) is not officially supported and may
394
+ lead to concurrent access exceptions and/or inconsistent state in the bean container.
395
+ ====
396
+
387
397
388
398
389
399
[[beans-beanname]]
@@ -6557,15 +6567,20 @@ classes, each depending on beans declared in the others:
6557
6567
----
6558
6568
6559
6569
There is another way to achieve the same result. Remember that `@Configuration` classes are
6560
- ultimately just another bean in the container - this means that they can take advantage
6561
- of `@Autowired` injection metadata just like any other bean!
6570
+ ultimately just another bean in the container: This means that they can take advantage of
6571
+ `@Autowired` and `@Value` injection etc just like any other bean!
6562
6572
6563
6573
[WARNING]
6564
6574
====
6565
6575
Make sure that the dependencies you inject that way are of the simplest kind only. `@Configuration`
6566
- classes are processed quite early during the initialization of the context and forcing a
6567
- dependency to be injected this way may lead to unexpected early initialization. Whenever possible,
6568
- resort to parameter-based injection as in the example above.
6576
+ classes are processed quite early during the initialization of the context and forcing a dependency
6577
+ to be injected this way may lead to unexpected early initialization. Whenever possible, resort to
6578
+ parameter-based injection as in the example above.
6579
+
6580
+ Also, be particularly careful with `BeanPostProcessor` and `BeanFactoryPostProcessor` definitions
6581
+ via `@Bean`. Those should usually be declared as `static @Bean` methods, not triggering the
6582
+ instantiation of their containing configuration class. Otherwise, `@Autowired` and `@Value` won't
6583
+ work on the configuration class itself since it is being created as a bean instance too early.
6569
6584
====
6570
6585
6571
6586
[source,java,indent=0]
0 commit comments