set value to Cacheable annotation from property file

别等时光非礼了梦想. 提交于 2020-01-30 11:15:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!