From b65390828ee2dba1d4e738de7072ed72ef7a2464 Mon Sep 17 00:00:00 2001 From: wakingrufus Date: Thu, 16 Oct 2025 16:52:45 -0500 Subject: [PATCH] Add a test for multiple bean registrars This commit add a test for multiple bean registrars imported by the same configuration class. See gh-35653 Signed-off-by: wakingrufus --- .../BeanRegistrarDslConfigurationTests.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-context/src/test/kotlin/org/springframework/context/annotation/BeanRegistrarDslConfigurationTests.kt b/spring-context/src/test/kotlin/org/springframework/context/annotation/BeanRegistrarDslConfigurationTests.kt index 07b5ff71ba9..35901f5dfdc 100644 --- a/spring-context/src/test/kotlin/org/springframework/context/annotation/BeanRegistrarDslConfigurationTests.kt +++ b/spring-context/src/test/kotlin/org/springframework/context/annotation/BeanRegistrarDslConfigurationTests.kt @@ -24,6 +24,7 @@ import org.springframework.beans.factory.InitializingBean import org.springframework.beans.factory.NoSuchBeanDefinitionException import org.springframework.beans.factory.config.BeanDefinition import org.springframework.beans.factory.getBean +import org.springframework.beans.factory.getBeanProvider import org.springframework.beans.factory.support.RootBeanDefinition import org.springframework.mock.env.MockEnvironment import java.util.function.Supplier @@ -77,6 +78,13 @@ class BeanRegistrarDslConfigurationTests { assertThat(context.getBean().foo).isEqualTo(context.getBean()) } + @Test + fun multipleBeanRegistrars() { + val context = AnnotationConfigApplicationContext(MultipleBeanRegistrarsKotlinConfiguration::class.java) + assertThat(context.getBeanProvider().singleOrNull()).isNotNull + assertThat(context.getBeanProvider().singleOrNull()).isNotNull + } + class Foo data class Bar(val foo: Foo) data class Baz(val message: String = "") @@ -90,6 +98,18 @@ class BeanRegistrarDslConfigurationTests { } + @Configuration + @Import(value = [FooRegistrar::class, BarRegistrar::class]) + internal class MultipleBeanRegistrarsKotlinConfiguration + + private class FooRegistrar : BeanRegistrarDsl({ + registerBean() + }) + + private class BarRegistrar : BeanRegistrarDsl({ + registerBean() + }) + @Configuration @Import(SampleBeanRegistrar::class) internal class BeanRegistrarKotlinConfiguration