Skip to content

Using Spring beans as a part of key in cache annotations (@Cacheable etc.) doesn't work [SPR-9578] #14212

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

10 votes, 12 watchers

Metadata

Metadata

Assignees

Labels

has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importin: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions