Expression Evaluation using Spring’s Expression Interface:-
The simple use of SpEL interfaces and its expression language. The following
code introduces the SpEL API to evaluate the literal string expression Hello
World.
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("'Hello World'");
String message = (String) exp.getValue();
The SpEL classes and interfaces you are most likely to use are
located in the packages org.springframework.expression and its sub
packages and spel.support.
The interface ExpressionParser is responsible for parsing an expression
string. In this example the expression string is a string literal denoted by the
surrounding single quotes. The interface Expression is responsible for
evaluating the previously defined expression string. There are two exceptions
that can be thrown, ParseException and EvaluationException when
calling parser.parseExpression and exp.getValue .
An example of method invocation, we call the concat method on the string literal.
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("'Hello World'.concat('!')");
String message = (String) exp.getValue();
The value of message is now Hello World!.