Add missing method BeanDefinitionBuilder.setFallback()

This commit is contained in:
Yanming Zhou 2024-02-29 17:18:48 +08:00 committed by Juergen Hoeller
parent 9a1e5eb8d7
commit 246ebd24bf
2 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ import org.springframework.util.ObjectUtils;
* @author Rod Johnson
* @author Rob Harrop
* @author Juergen Hoeller
* @author Yanming Zhou
* @since 2.0
*/
public final class BeanDefinitionBuilder {
@ -348,6 +349,15 @@ public final class BeanDefinitionBuilder {
return this;
}
/**
* Set whether this bean is a fallback autowire candidate.
* @since 6.2
*/
public BeanDefinitionBuilder setFallback(boolean fallback) {
this.beanDefinition.setFallback(fallback);
return this;
}
/**
* Set the role of this definition.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson
* @author Juergen Hoeller
* @author Stephane Nicoll
* @author Yanming Zhou
*/
class BeanDefinitionBuilderTests {
@ -125,6 +126,12 @@ class BeanDefinitionBuilderTests {
.setPrimary(true).getBeanDefinition().isPrimary()).isTrue();
}
@Test
void builderWithFallback() {
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
.setFallback(true).getBeanDefinition().isFallback()).isTrue();
}
@Test
void builderWithRole() {
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)