At https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt the comment shows how to define Spring Beans via the new "Functional bean definition Kotlin DSL". I also found https://github.com/sdeleuze/spring-kotlin-functional. However, this example uses just plain Spring and not Spring Boot. Any hint how to use the DSL together with Spring Boot is appreciated.
How to use "Functional bean definition Kotlin DSL" with Spring Boot and Spring WebFlux?
12.2k views Asked by Juergen Zimmermann At
4
There are 4 answers
0
On
You can define your beans in *Config.kt file and implement initalize method of ApplicationContextInitializer interface.
override fun initialize(applicationContext: GenericApplicationContext) {
....
}
Some bean definition here.
bean<XServiceImpl>("xService")
bean("beanName") {
BeanConstructor(ref("refBeanName"))
}
0
On
That same example project you mentioned has a boot git branch, with the BeanDefinitionDsl configuration for Spring Boot in a Beans.kt
file. That is not how you should use git branches...
Spring Boot is based on Java Config, but should allow experimental support of user-defined functional bean declaration DSL via
ApplicationContextInitializer
support as described here.In practice, you should be able to declare your beans for example in a
Beans.kt
file containing abeans()
function.Then in order to make it taken in account by Boot when running
main()
and tests, create anApplicationContextInitializer
class as following:And ultimately, declare this initializer in your
application.properties
file:You will find a full example here and can also follow this issue about dedicated Spring Boot support for functional bean registration.