[英]set value to Cacheable annotation from property file
I'm using Spring Cacheable annotation and at the moment I'm struggling with a way of adding the cache name from property file. 我正在使用Spring Cacheable批注,此刻正在努力从属性文件中添加缓存名称。
I tried: 我试过了:
@Cacheable("${some.cache.name}")
and 和
@Cacheable("#{'${some.cache.name}'}")
There is a SPI to do that that is much more powerful than just using SpEL. 有一个SPI可以比仅使用SpEL强大得多。 You can implement CacheResolver
and resolve cache instance(s) at runtime. 您可以实现CacheResolver
并在运行时解析缓存实例。 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
. 您可以指定CacheResolver
使用每个注释,在类级别@CacheConfig
或全球范围内通过实施CacheConfigurer
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.