这是咒语表达式:
@Cacheable(value = "Cache",
key = "(#request).getToken().hashCode()",
unless = "#result == null")
错误:org.springframework.expression.spel.SpelEvaluationException:EL1011E:方法调用:尝试在空上下文对象上调用方法 getAuthenticationRequest()
如何解决这个问题?
我认为答案就在 Javadocs 中:
/**
* Spring Expression Language (SpEL) expression for computing the key dynamically.
* <p>Default is {@code ""}, meaning all method parameters are considered as a key,
* unless a custom {@link #keyGenerator} has been configured.
* <p>The SpEL expression evaluates against a dedicated context that provides the
* following meta-data:
* <ul>
* <li>{@code #root.method}, {@code #root.target}, and {@code #root.caches} for
* references to the {@link java.lang.reflect.Method method}, target object, and
* affected cache(s) respectively.</li>
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
* ({@code #root.targetClass}) are also available.
* <li>Method arguments can be accessed by index. For instance the second argument
* can be accessed via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
* can also be accessed by name if that information is available.</li>
* </ul>
*/
String key() default "";
我假设你的
request
是一个参数名称。显然,您的情况无法获得此类信息。尝试使用 -parameters
选项编译您的项目。