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:
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.context.support
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider
|
||||
import org.springframework.beans.factory.config.BeanDefinition
|
||||
import org.springframework.beans.factory.config.BeanDefinitionCustomizer
|
||||
import org.springframework.beans.factory.getBeanProvider
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils
|
||||
import org.springframework.context.ApplicationContextInitializer
|
||||
import org.springframework.core.env.ConfigurableEnvironment
|
||||
@@ -81,10 +83,10 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
|
||||
internal val children = arrayListOf<BeanDefinitionDsl>()
|
||||
|
||||
/**
|
||||
* Access to the context for advanced use-cases.
|
||||
* @since 5.1
|
||||
* @see provider
|
||||
*/
|
||||
lateinit var context: GenericApplicationContext
|
||||
@PublishedApi
|
||||
internal lateinit var context: GenericApplicationContext
|
||||
|
||||
/**
|
||||
* Shortcut for `context.environment`
|
||||
@@ -245,6 +247,15 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
|
||||
else -> context.getBean(name, T::class.java)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an provider for the specified bean, allowing for lazy on-demand retrieval
|
||||
* of instances, including availability and uniqueness options.
|
||||
* @since 5.1.1
|
||||
* @see org.springframework.beans.factory.BeanFactory.getBeanProvider
|
||||
*/
|
||||
inline fun <reified T : Any> provider() : ObjectProvider<T> = context.getBeanProvider()
|
||||
|
||||
/**
|
||||
* Take in account bean definitions enclosed in the provided lambda only when the
|
||||
* specified profile is active.
|
||||
|
||||
Reference in New Issue
Block a user