Description
Juha Syrjälä opened SPR-9578 and commented
I am trying to use a result of method call to a spring bean as a part of the cache key, but that doesn't seem to work.
@Inject
private KeyCreatorBean keyCreatorBean;
@Cacheable
(value = "cacheName", key = "{@keyCreatorBean
.createKey, #p0}")
@Override
public List<Examples> getExamples(ExampleId exampleId) {
Results in this kind of stack trace:
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 1): Field or property 'keyCreatorBean' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject'
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:72)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
at org.springframework.expression.spel.ast.InlineList.getValueInternal(InlineList.java:86)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:88)
at org.springframework.cache.interceptor.ExpressionEvaluator.key(ExpressionEvaluator.java:80)
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.generateKey(CacheAspectSupport.java:464)
Reference URL: http://stackoverflow.com/q/11396911/1431
Issue Links:
- Cacheable condition SpEL cannot invoke bean methods [SPR-13812] #18385 Cacheable condition SpEL cannot invoke bean methods ("duplicates")
- @Cachable condition should allow referencing return value [SPR-8871] #13512
@Cachable
condition should allow referencing return value - Allow @Cacheable method to return java.util.Optional variant of cached value [SPR-14230] #18804 Allow
@Cacheable
method to return java.util.Optional variant of cached value
10 votes, 12 watchers