You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Relax singleton enforcement for Bean Overrides in the TestContext framework
In gh-33602, we introduced strict singleton enforcement for bean
overrides -- for example, for @MockitoBean, @TestBean, etc. However,
the use of BeanFactory#isSingleton(beanName) can result in a
BeanCreationException for certain beans, such as a Spring Data JPA
FactoryBean for a JpaRepository.
In light of that, this commit relaxes the singleton enforcement in
BeanOverrideBeanFactoryPostProcessor by only checking the result of
BeanDefinition#isSingleton() for existing bean definitions.
This commit also updates the Javadoc and reference documentation to
reflect the status quo.
See gh-33602Closesgh-33800
Copy file name to clipboardExpand all lines: spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java
+11-4
Original file line number
Diff line number
Diff line change
@@ -197,8 +197,7 @@ else if (Boolean.getBoolean(AbstractAotProcessor.AOT_PROCESSING)) {
197
197
// Now we have an instance (the override) that we can manually register as a singleton.
198
198
//
199
199
// However, we need to remove any existing singleton instance -- for example, a
200
-
// manually registered singleton or a singleton that was registered as a side effect
201
-
// of the isSingleton() check in validateBeanDefinition().
200
+
// manually registered singleton.
202
201
//
203
202
// As a bonus, by manually registering a singleton during "AOT processing", we allow
204
203
// GenericApplicationContext's preDetermineBeanType() method to transparently register
Copy file name to clipboardExpand all lines: spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java
0 commit comments