Includes a minor change to improve support for kotlin context receiver. I mark this PR as a draft for now because context receiver is still experimental so:
- There might be changes in the future in context receivers, making this PR obsolete (or at least requires to modify it)
- I cannot add unit tests without activating the experimental feature, which I'd rather not.
The PR only fix constructor call when a class is annotated with a context receiver. Concretely, it means that this PR allows:
context(AnotherBeanType)
@Component class MyBean() {
// ... class content ...
}
Note that, the above construct works on a project without Kotlin support. In such case, no Kotlin reflection is involved, and the "java" constructor is called instead.
For those interested in testing, I've setup a small demo project that:
- Use context receiver on @Bean annotated method (already works with Spring-Boot 3.1.1)
- Contains commented constructor based component (because a change is required for it to work)
- Contains a branch
feat/by-constructor
that shows constructor binding works when kotlin spring plugin is removed from build (but it forces to open all classes manually).
Comment From: sdeleuze
Thanks for this PR and for the reproducer, let's consider it for merging when context receivers won't be experimental anymore, see related https://github.com/Kotlin/KEEP/issues/259 issue.
Comment From: sdeleuze
Given the status of the discussion on Kotlin side where everything is still being discussed on design side, I have the feeling we are still pretty far from something we can support in Spring. A consequence, I close this PR unmerged. Let's reconsider later when there is something more concrete.