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
Use the field name as a fallback qualifier for Bean Overriding
This commit harmonizes how a candidate bean definition is determined
for overriding using `@TestBean`, `@MockitoBean`, and `@MockitoSpyBean`.
Previously, a qualifier was necessary even if the name of the annotated
field matches the name of a candidate. After this commit, such candidate
will be picked up transparently, the same it is done for regular
autowiring.
This commit also reviews the documentation of the feature as considering
the field means that its name is taken into account to compute a cache
key if by-type lookup is requested.
Closesgh-32939
Copy file name to clipboardexpand all lines: spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java
+7
Original file line number
Diff line number
Diff line change
@@ -259,6 +259,13 @@ private Set<String> getExistingBeanNamesByType(ConfigurableListableBeanFactory b
259
259
else {
260
260
beans.removeIf(ScopedProxyUtils::isScopedTarget);
261
261
}
262
+
// In case of multiple matches, last resort fallback on the field's name
0 commit comments