Replace context by provider<T>() in Kotlin bean DSL

Spring Framework 5.1.0 exposed by mistake context in the Kotlin bean DSL
API in order to fix SPR-16269. Now that BeanFactory#getBeanprovider is
available, it should be exposed via a provider<Foo>() function in order
to provide a more clean API instead.

Issue: SPR-17352
This commit is contained in:
Sebastien Deleuze
2018-10-08 13:08:00 +02:00
parent 635d2146db
commit af6a5566a3
2 changed files with 18 additions and 7 deletions

View File

@@ -20,11 +20,11 @@ import org.junit.Assert.*
import org.junit.Test
import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.beans.factory.getBean
import org.springframework.beans.factory.getBeansOfType
import org.springframework.context.support.BeanDefinitionDsl.*
import org.springframework.core.env.SimpleCommandLinePropertySource
import org.springframework.core.env.get
import org.springframework.mock.env.MockPropertySource
import java.util.stream.Collectors
@Suppress("UNUSED_EXPRESSION")
class BeanDefinitionDslTests {
@@ -127,12 +127,12 @@ class BeanDefinitionDslTests {
}
}
@Test // SPR-16269
fun `Provide access to the context for allowing calling advanced features like getBeansOfType`() {
@Test // SPR-17352
fun `Retrieve multiple beans via a bean provider`() {
val beans = beans {
bean<Foo>()
bean<Foo>()
bean { BarBar(context.getBeansOfType<Foo>().values) }
bean { BarBar(provider<Foo>().stream().collect(Collectors.toList())) }
}
val context = GenericApplicationContext().apply {