Support creating beans from Kotlin callable references
This commit updates Kotlin beans DSL in order to support creating beans using callable references with autowired parameters. Type resolution is implemented using Kotlin reified type parameters without requiring reflection. Closes gh-21845
This commit is contained in:
@@ -156,6 +156,19 @@ class BeanDefinitionDslTests {
|
||||
}
|
||||
context.getBean<Baz>()
|
||||
}
|
||||
|
||||
@Test // gh-21845
|
||||
fun `Declare beans leveraging callable reference`() {
|
||||
val beans = beans {
|
||||
bean<Bar>()
|
||||
bean(::baz)
|
||||
}
|
||||
val context = GenericApplicationContext().apply {
|
||||
beans.initialize(this)
|
||||
refresh()
|
||||
}
|
||||
context.getBean<Baz>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -164,3 +177,5 @@ class Bar
|
||||
class Baz(val bar: Bar)
|
||||
class FooFoo(val name: String)
|
||||
class BarBar(val foos: Collection<Foo>)
|
||||
|
||||
fun baz(bar: Bar) = Baz(bar)
|
||||
|
||||
Reference in New Issue
Block a user