|
35 | 35 | import java.util.stream.Collectors;
|
36 | 36 | import lombok.Data;
|
37 | 37 | import lombok.EqualsAndHashCode;
|
38 |
| -import org.springframework.aop.support.AopUtils; |
39 | 38 | import org.springframework.context.expression.AnnotatedElementKey;
|
40 | 39 | import org.springframework.context.expression.CachedExpressionEvaluator;
|
41 | 40 | import org.springframework.context.expression.MethodBasedEvaluationContext;
|
42 |
| -import org.springframework.core.DefaultParameterNameDiscoverer; |
43 |
| -import org.springframework.core.ParameterNameDiscoverer; |
44 | 41 | import org.springframework.core.convert.ConversionService;
|
45 | 42 | import org.springframework.core.convert.TypeDescriptor;
|
46 | 43 | import org.springframework.expression.EvaluationContext;
|
|
52 | 49 | @EqualsAndHashCode(callSuper = false)
|
53 | 50 | public class SpelKeyGenerator extends CachedExpressionEvaluator implements KeyGenerator {
|
54 | 51 | private final ConversionService conversionService;
|
55 |
| - private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); |
56 | 52 | private final Map<ExpressionKey, Expression> conditionCache = new ConcurrentHashMap<>();
|
57 | 53 | private final Map<AnnotatedElementKey, Method> targetMethodCache = new ConcurrentHashMap<>();
|
58 | 54 |
|
59 | 55 | @Override
|
60 | 56 | public List<String> resolveKeys(final String lockKeyPrefix, final String expression, final Object object, final Method method, final Object[] args) {
|
61 |
| - final AnnotatedElementKey annotatedElementKey = new AnnotatedElementKey(method, object.getClass()); |
62 |
| - final Method targetMethod = this.targetMethodCache.computeIfAbsent(annotatedElementKey, key -> AopUtils.getMostSpecificMethod(method, object.getClass())); |
63 |
| - final EvaluationContext context = new MethodBasedEvaluationContext(object, targetMethod, args, this.parameterNameDiscoverer); |
| 57 | + final EvaluationContext context = new MethodBasedEvaluationContext(object, method, args, super.getParameterNameDiscoverer()); |
64 | 58 | context.setVariable("executionPath", object.getClass().getCanonicalName() + "." + method.getName());
|
65 | 59 |
|
66 |
| - final List<String> keys = convertResultToList(getExpression(this.conditionCache, annotatedElementKey, expression).getValue(context)); |
| 60 | + final List<String> keys = convertResultToList(getExpression(this.conditionCache, new AnnotatedElementKey(method, object.getClass()), expression).getValue(context)); |
67 | 61 |
|
68 | 62 | if (keys.stream().anyMatch(Objects::isNull)) {
|
69 | 63 | throw new EvaluationConvertException("null keys are not supported: " + keys);
|
|
0 commit comments