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:
Sebastien Deleuze
2019-03-27 14:30:39 +01:00
parent c9857702e4
commit fb1da01410
3 changed files with 867 additions and 5 deletions

View File

@@ -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)