Spring EL - 调用静态接口方法

Lio*_*ior 3 spring-el

有没有办法在 SpEL 中调用静态接口方法?例如:

T(java.util.stream.IntStream).of(new Integer[]{1,2,3}).sum()
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到此错误:Problem locating method of on type class java.lang.Class

Art*_*lan 5

您缺少向我们展示更多堆栈跟踪:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1033E: Method call of 'of' is ambiguous, supported type conversions allow multiple variants to match
at org.springframework.expression.spel.support.ReflectiveMethodResolver.resolve(ReflectiveMethodResolver.java:211)
Run Code Online (Sandbox Code Playgroud)

它无法在运行时通过反射解析正确的方法,只是of()因为IntStream.

这对我有用:

ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("T(java.util.stream.IntStream).of(1,2,3).sum()");

assertThat(expression.getValue()).isEqualTo(6);
Run Code Online (Sandbox Code Playgroud)