diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java index daff62de6e5..78164079511 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java @@ -101,10 +101,12 @@ class BeanOverrideBeanFactoryPostProcessor implements BeanFactoryPostProcessor, * Copy certain details of a {@link BeanDefinition} to the definition created by * this processor for a given {@link OverrideMetadata}. *

The default implementation copies the {@linkplain BeanDefinition#isPrimary() - * primary flag} and the {@linkplain BeanDefinition#getScope() scope}. + * primary flag}, @{@linkplain BeanDefinition#isFallback() fallback flag} + * and the {@linkplain BeanDefinition#getScope() scope}. */ protected void copyBeanDefinitionDetails(BeanDefinition from, RootBeanDefinition to) { to.setPrimary(from.isPrimary()); + to.setFallback(from.isFallback()); to.setScope(from.getScope()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java index 79713a42de2..8b8cefaf513 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java @@ -156,12 +156,13 @@ class BeanOverrideBeanFactoryPostProcessorTests { } @Test - void copyDefinitionPrimaryAndScope() { + void copyDefinitionPrimaryFallbackAndScope() { AnnotationConfigApplicationContext context = createContext(SingletonBean.class); context.getBeanFactory().registerScope("customScope", new SimpleThreadScope()); RootBeanDefinition definition = new RootBeanDefinition(String.class, () -> "ORIGINAL"); definition.setScope("customScope"); definition.setPrimary(true); + definition.setFallback(true); context.registerBeanDefinition("singleton", definition); context.register(SingletonBean.class); @@ -169,6 +170,7 @@ class BeanOverrideBeanFactoryPostProcessorTests { assertThat(context.getBeanDefinition("singleton")) .isNotSameAs(definition) .matches(BeanDefinition::isPrimary, "isPrimary") + .matches(BeanDefinition::isFallback, "isFallback") .satisfies(d -> assertThat(d.getScope()).isEqualTo("customScope")) .matches(Predicate.not(BeanDefinition::isSingleton), "!isSingleton") .matches(Predicate.not(BeanDefinition::isPrototype), "!isPrototype");