问题
I'm using Spring Cacheable annotation and at the moment I'm struggling with a way of adding the cache name from property file.
I tried:
@Cacheable("${some.cache.name}")
and
@Cacheable("#{'${some.cache.name}'}")
回答1:
There is a SPI to do that that is much more powerful than just using SpEL. You can implement CacheResolver
and resolve cache instance(s) at runtime. You could use the annotated type or any name that is provided via the annotation.
You can specify the CacheResolver
per annotation, at class-level using @CacheConfig
or globally by implementing CacheConfigurer
.
Check the documentation for more details
来源:https://stackoverflow.com/questions/48281219/set-value-to-cacheable-annotation-from-property-file