Limit ref() and provider() visibility in Kotlin DSL [SPR-17648] #22177
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Sébastien Deleuze opened SPR-17648 and commented
Current Kotlin bean DSL makes it possible to shoot yourself in the foot easily by allowing to write:
Which will trigger
java.lang.IllegalStateException: org.springframework.context.support.GenericApplicationContext@2c532cd8 has not been refreshed yet
.We should only expose
ref()
andprovider()
in the supplier responsible for providing the bean, since it will be call at the right time of the lifecycle.We could maybe introduce some kind of
BeanDefinitionContext
:And change
crossinline function: () -> T
tocrossinline function: BeanDefinitionContext.() -> T
in the bean supplier variant.Additional notes:
ObjectProvider
methods, exposeSequence
instead ofStream
, etc.router()
variant that leverages thisBeanDefinitionContext
since this is a common use case.No further details from SPR-17648
The text was updated successfully, but these errors were encountered: