Skip to content

Commit b17d1c5

Browse files
committed
Polishing BeanOverrideBeanFactoryPostProcessor to also copy isFallback
1 parent 6f6e25b commit b17d1c5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ private void postProcessWithRegistry(ConfigurableListableBeanFactory beanFactory
101101
* Copy certain details of a {@link BeanDefinition} to the definition created by
102102
* this processor for a given {@link OverrideMetadata}.
103103
* <p>The default implementation copies the {@linkplain BeanDefinition#isPrimary()
104-
* primary flag} and the {@linkplain BeanDefinition#getScope() scope}.
104+
* primary flag}, @{@linkplain BeanDefinition#isFallback() fallback flag}
105+
* and the {@linkplain BeanDefinition#getScope() scope}.
105106
*/
106107
protected void copyBeanDefinitionDetails(BeanDefinition from, RootBeanDefinition to) {
107108
to.setPrimary(from.isPrimary());
109+
to.setFallback(from.isFallback());
108110
to.setScope(from.getScope());
109111
}
110112

spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,21 @@ void allowReplaceDefinitionWhenSingletonDefinitionPresent() {
156156
}
157157

158158
@Test
159-
void copyDefinitionPrimaryAndScope() {
159+
void copyDefinitionPrimaryFallbackAndScope() {
160160
AnnotationConfigApplicationContext context = createContext(SingletonBean.class);
161161
context.getBeanFactory().registerScope("customScope", new SimpleThreadScope());
162162
RootBeanDefinition definition = new RootBeanDefinition(String.class, () -> "ORIGINAL");
163163
definition.setScope("customScope");
164164
definition.setPrimary(true);
165+
definition.setFallback(true);
165166
context.registerBeanDefinition("singleton", definition);
166167
context.register(SingletonBean.class);
167168

168169
assertThatNoException().isThrownBy(context::refresh);
169170
assertThat(context.getBeanDefinition("singleton"))
170171
.isNotSameAs(definition)
171172
.matches(BeanDefinition::isPrimary, "isPrimary")
173+
.matches(BeanDefinition::isFallback, "isFallback")
172174
.satisfies(d -> assertThat(d.getScope()).isEqualTo("customScope"))
173175
.matches(Predicate.not(BeanDefinition::isSingleton), "!isSingleton")
174176
.matches(Predicate.not(BeanDefinition::isPrototype), "!isPrototype");

0 commit comments

Comments
 (0)