Initialize beans with coroutine context #26553
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: declined
A suggestion or change that we don't feel we should currently apply
theme: kotlin
An issue related to Kotlin support
Currently there are a few ways to initialize beans, but i did not find a way to initialize a class that require a coroutine context.
For example we can take the following class:
To initialize this service as a bean, it can not be marked as a
@Component
and should be registered as a@Bean
. It would be great if the following was possible:Register
@Bean
with a suspend function. e.g.Add bean using
BeanDefinitionDsl
. e.g.This also leads to other places where a coroutine context would be helpful, or if the infrastructure would be based on callbacks / futures. For example in my project we have a use-case where we use the
beans
dsl to register beans triggered from aApplicationListener<ContextRefreshedEvent>
. It would be great ifonApplicationEvent
could also have a suspend version so thecoBeans
dsl could be used from there as well.Currently the only way i could find to overcome this is using
runBlocking
in those places, which is not recommended and can cause problems.The text was updated successfully, but these errors were encountered: