mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-23 22:59:03 +00:00
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 <wakingrufus@gmail.com>
This commit is contained in:
committed by
Sébastien Deleuze
parent
cab46c74d5
commit
b65390828e
+20
@@ -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<Bar>().foo).isEqualTo(context.getBean<Foo>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun multipleBeanRegistrars() {
|
||||
val context = AnnotationConfigApplicationContext(MultipleBeanRegistrarsKotlinConfiguration::class.java)
|
||||
assertThat(context.getBeanProvider<Foo>().singleOrNull()).isNotNull
|
||||
assertThat(context.getBeanProvider<Bar>().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<Foo>()
|
||||
})
|
||||
|
||||
private class BarRegistrar : BeanRegistrarDsl({
|
||||
registerBean<Bar>()
|
||||
})
|
||||
|
||||
@Configuration
|
||||
@Import(SampleBeanRegistrar::class)
|
||||
internal class BeanRegistrarKotlinConfiguration
|
||||
|
||||
Reference in New Issue
Block a user