如何使以下工作: - 一個Spring應用程序緩存@Cacheable註釋 - 另一個爲緩存創建鍵的spring bean(KeyCreatorBean )。使用Spring bean作爲@Cacheable註釋的關鍵
所以代碼看起來像這樣。
@Inject
private KeyCreatorBean keyCreatorBean;
@Cacheable(value = "cacheName", key = "{@keyCreatorBean.createKey, #p0}")
@Override
public List<Examples> getExamples(ExampleId exampleId) {
...
但是上面的代碼不起作用:它提供了以下異常:
Caused by: org.springframework.expression.spel.SpelEvaluationException:
EL1057E:(pos 2): No bean resolver registered in the context to resolve access to bean 'keyCreatorBean'
嘗試像'#{keyCreatorBean.method}',而不是'@keyCreatorBean.method'.Just隨機猜測。 – xyz 2012-07-09 16:21:54
有點相關的問題:http://stackoverflow.com/questions/5749730/bean-creation-using-spel-hibernate – 2012-07-10 06:44:48
你可以試試這個:http://stackoverflow.com/a/8142249/799562''但需要實現'org.springframework.cache.interceptor.KeyGenerator'。 –
micfra
2012-07-10 11:13:53