Spring @Cacheable with SpEL键:始终计算为null [英] Spring @Cacheable with SpEL key: always evaluates to null
问题描述
我在使用@Cacheable并使用基于Spring表达式语言的自定义键时遇到问题.我有以下代码
I am having a problem with @Cacheable and using a custom key based on Spring expression language. I have the following code
@Cacheable(value = "myCache", key = "#providerDTO.identifier")
ClientVO loadClientVOByProviderDTO(ProviderDTO providerDTO);
这将引发以下错误
org.springframework.expression.spel.SpelEvaluation Exception: EL1007Epos 0): Field or property 'identifier' cannot be found on null
providerDTO参数不为null,我已多次验证.文档说这应该工作,所以我很困惑.文档给出了以下示例
The providerDTO argument is not null, I have verified this many times. The docs say that this should work so I am very confused. The docs give the following example
@Cacheable(value="books", key="#isbn.rawNumber")
我也尝试过使用静态方法.这将引发NullPointerException,因为在这里providerDTO为null.
I have also tried with a static method. This throws a NullPointerException because the providerDTO is null here.
public static String cacheKey(ProviderDTO providerDTO)
{
return providerDTO.identifier + "-" + providerDTO.clientID + "-" + providerDTO.clubID;
}
我该如何调试以找出正在发生的情况?这是Spring 3.2.4-RELEASE. @Cacheable标记在接口上,但是据我所知,它仍然可以正常工作.
How can I debug this to find out what is happening? This is Spring 3.2.4-RELEASE. The @Cacheable tag is on an interface, but I am using standard spring AOP and not AspectJ so as far as I understand this should still work fine.
推荐答案
SpelEvaluationException:EL1007E:(pos 43):字段的可能重复项或无法在null上找到属性"group" 和 spring @Cacheable with Ehcache,请为有效对象找到null –我相信您在编译时没有调试信息.请检查您的Maven配置;您可能要在此处发布相关位.在您的POM(或父POM)中搜索maven-compiler-plugin
和一行,例如:
Possible duplicate of SpelEvaluationException: EL1007E:(pos 43): Field or property 'group' cannot be found on null and spring @Cacheable with Ehcache, spel find null for valid object – I believe you compile without debug information. Please check your Maven configuration; you might want to post the relevant bits here. Search your POM (or parent POM) for the maven-compiler-plugin
and a line such as:
<debug>false</debug>
这篇关于Spring @Cacheable with SpEL键:始终计算为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!