【发布时间】:2017-11-14 08:41:34
【问题描述】:
当我尝试使用 SPeL 表达式注入一个值时,它在 Java 中有效,但在 Kotlin 中无效。编译器说
Error:(13, 25) Kotlin: An annotation parameter must be a compile-time constant
代码:
@SpringBootApplication
open class DeDup(@Value("#{new java.io.File('${roots}')}") val roots: Set<File>,
@Value("algo") val hashAlgo: String,
@Value("types")val fileTypes: List<String>) {
}
fun main(args: Array<String>) {
SpringApplication.run(DeDup::class.java, *args)
}
嗯...新闻快讯 Kotlin 编译器:它是一个常量!编译器清楚地知道它是一个 SPeL 表达式并且不喜欢它。
我的问题:
为什么 Kotlin 不喜欢 SPeL?这是一个构造注入(或者是它)并且不违反不变性。
这是编译器错误吗?消息无疑是错误的。
【问题讨论】:
标签: spring spring-boot kotlin spring-el