gpt4 book ai didi

Spring 缓存 key 生成器

转载 作者:行者123 更新时间:2023-12-02 11:57:32 25 4
gpt4 key购买 nike

我刚刚开始研究 Spring 缓存。

我的服务方式是...

@Override
@Cacheable(value="profile", **key**="personId" )
public String cpuService2(Long personId, String personAddress){
return "CachedMessage";
}

没有 key 子句,不会抛出异常并假定两个参数自动生成以进行缓存但是有了键,当我调用这个方法时,抛出异常...

Exception in thread "main" org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'personId' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject'
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:246)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:112)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:107)
at org.springframework.expression.spel.ast.OpGT.getValueInternal(OpGT.java:37)
at org.springframework.expression.spel.ast.OpGT.getValueInternal(OpGT.java:29)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:98)
at org.springframework.cache.interceptor.ExpressionEvaluator.condition(ExpressionEvaluator.java:99)
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.isConditionPassing(CacheAspectSupport.java:462)
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.isConditionPassing(CacheAspectSupport.java:456)
at org.springframework.cache.interceptor.CacheAspectSupport.inspectCacheables(CacheAspectSupport.java:292)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:199)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy5.cpuService3(Unknown Source)
at pack100_cache.pack020CacheKey.TestSimpleBean.main(TestSimpleBean.java:34)

搜索了文档但没有线索。希望有人能解决这个问题。

最佳答案

您缺少 personId 前面的 #

@Override
@Cacheable(value="profile", key="#personId" )
public String cpuService2(Long personId, String personAddress){
return "CachedMessage";
}

caching abstraction chapter有很多您想要做的事情的例子。

关于Spring 缓存 key 生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23269975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com