Spring 4 @cacheable注释:如何为自定义密钥生成器添加属性?

时间:2017-09-08 15:27:10

标签: java spring annotations ehcache

在我的Java项目中,我将spring迁移到 - > 4.3.4并将ehcache-spring-annotation迁移到http://www.springframework.org/schema/cache

我在定义缓存customkeygenerator的属性时遇到问题:

 @Cacheable(value = "cacheDAO", keyGenerator = @KeyGenerator(name = "CacheKeyGenerator",
        properties = { @Property(name = "useReflection", value = "true"),
                       @Property(name = "checkforCycles", value = "true"),
                       @Property(name = "includeMethod", value = "false") })

似乎无法通过@keyGenerator注释定义useReflection,checkForCycles或includeMethod。

你可以帮我配置一下吗?它如何与春天4一起工作? 如果你不理解我的问题,请告诉我。

谢谢!

1 个答案:

答案 0 :(得分:0)

根据内联似乎不可能的the documentation。但是,从同一个密钥生成器配置特定bean但将不同的属性值映射到不同的bean名称是非常简单的。然后在@Cacheable注释中引用确切的一个。