Reputation: 43
In Spring Boot (with Java) I usually put the cache names in static final strings, like this:
public static final String MY_CACHE_NAME = "cache_name"
@Cacheable(value = MY_CACHE_NAME)
But, when I have a java class with this cache names and I try to use in a Kotlin cached method, the Eclipse tells me this is not a "compile-time constant". Is there a way to solve this?
Outside eclipse, everything goes fine...
Upvotes: 1
Views: 1182
Reputation: 89668
That's quite odd, this should definitely work. You probably have a configuration problem. Check if your Kotlin plugin and your project use the same version of Kotlin, different versions often lead to odd compiler errors. Use the latest version in both places if possible.
This is the example code that I tried that worked perfectly well on 1.1.50
(it's nonsense, but it compiles):
MyConstants.java
public class MyConstants {
public static final String MY_CACHE_NAME = "cache_name";
}
DemoApplication.kt
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
SpringApplication.run(DemoApplication::class.java, *args)
}
@Cacheable(MyConstants.MY_CACHE_NAME)
fun someFunction() {}
Upvotes: 1