Skip to content

Commit

Permalink
fix compatible problem in Spring 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
areyouok committed Jan 30, 2018
1 parent 7d716d3 commit d0b127b
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

import com.alicp.jetcache.CacheConfigException;
import com.alicp.jetcache.CacheException;
import com.alicp.jetcache.anno.CacheConsts;
import com.alicp.jetcache.anno.support.CacheAnnoConfig;
import org.mvel2.MVEL;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.SpelCompilerMode;
import org.springframework.expression.spel.SpelParserConfiguration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.function.Function;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -93,10 +91,24 @@ class SpelEvaluator implements Function<Object, Object> {

private static ExpressionParser parser;

static{
SpelParserConfiguration config = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE,
SpelEvaluator.class.getClassLoader());
parser = new SpelExpressionParser(config);
static {
try {
//since spring 4.1
Class modeClass = Class.forName("org.springframework.expression.spel.SpelCompilerMode");

try {
Constructor<SpelParserConfiguration> c = SpelParserConfiguration.class
.getConstructor(modeClass, ClassLoader.class);
Object mode = modeClass.getField("IMMEDIATE").get(null);
SpelParserConfiguration config = c.newInstance(mode, SpelEvaluator.class.getClassLoader());
parser = new SpelExpressionParser(config);
} catch (Exception e) {
throw new CacheException(e);
}
} catch (ClassNotFoundException e) {
parser = new SpelExpressionParser();
}

}

private final Expression expression;
Expand Down

0 comments on commit d0b127b

Please sign in to comment.