diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java index 362737c9ee..d82d66bd75 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java @@ -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. */ diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java index 7a6b938ea1..5cc074407c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java @@ -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)