【发布时间】:2019-04-27 22:58:58
【问题描述】:
我有一个使用 IntelliJ 2019.1 打开的 Spring Boot 2 + Kotlin 应用程序。
在这个应用程序中,我用@Component 注释了一些 Kotlin 对象。示例:
@Component
object MyObject: MyInterface {
// code
}
我有许多不同的 MyInterface 实现(都带有 Kotlin 对象),我想将它们全部注入另一个 bean 的列表中。示例:
@Component
class MyComponent @Autowired constructor(private val objects: List<MyInterface>) {
// code
}
代码运行正确(bean 被注入列表 objects)但 IntelliJ 显示错误提示:
无法自动接线。没有豆子'?扩展 MyInterface' 或 'List 的类型。
如果我在“MyObject”中将“object”更改为“class”,错误就会消失。
我的问题是:
- 是 IntelliJ 的问题吗?
- 不建议使用
@Component注释 Kotlin 对象吗?
【问题讨论】:
标签: spring intellij-idea kotlin