Overview
Due to interest from the community (see comments in #33602), we have decided to reinstate support for overriding non-singleton beans via the Bean Override mechanism -- for example, when using @MockitoBean
, @MockitoSpyBean
, and @TestBean
.
Rationale
When #33602 was raised, our Bean Override support always created a "pseudo" bean definition for each overridden bean. That caused problems in general but especially for AOT support.
While implementing AOT support, we stopped registering pseudo bean definitions for existing bean definitions (see commits 461f1724b70166da7d6535fc3bc2a9d589268021 and 5ddeb06640c379448f943b1ae24f5ef2facccc37).
And in conjunction with #33800 we relaxed the restrictions for singleton enforcement even further (see commit 81d89f478aa2441ecfa90907ba21b7cc20152059).
Consequently, it should now be possible to support Bean Overrides for non-singletons, for both standard JVM and AOT runtimes. However, we should document that non-singletons will effectively be converted to singletons when overridden, and we should log a warning as well.
Related Issues
-
33602
-
32933
-
33800