Closed
Description
Stéphane Nicoll opened SPR-13812 and commented
The condition
attribute does not allow to use bean references. Assuming the following setup and a securityChecker
bean with the requested method
@Cacheable(cacheNames = "myCache", condition = "@securityChecker.isSecured()")
We get
org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'securityChecker'
at org.springframework.expression.spel.ast.BeanReference.getValueInternal(BeanReference.java:48) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:51) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.ExpressionEvaluator.condition(ExpressionEvaluator.java:119) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.isConditionPassing(CacheAspectSupport.java:607) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.isConditionPassing(CacheAspectSupport.java:481) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(CacheAspectSupport.java:433) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:336) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:302) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
Affects: 4.2 GA
Reference URL: http://stackoverflow.com/questions/34366465/bypass-cacheable-for-unauthenticated-requests
Issue Links:
- Using Spring beans as a part of key in cache annotations (@Cacheable etc.) doesn't work [SPR-9578] #14212 Using Spring beans as a part of key in cache annotations (
@Cacheable
etc.) doesn't work ("is duplicated by")