Spring Expression Language (SpEL):-
SpEL is an exression language supporting the features of querying and manipulating an object graph at runtime.
There are several existing expression languages like MVEL, OGNL and JBoss EL. Every EL is developed with some purpose in mind. SpEL is created to help the Spring porfolio products. The syntax used for the SpEL is same like Unified EL.
Another advantage of SpEL is it can work independently without depending on the Spring environment. In the following sections, you will read the complete details on SpEL API and Features the Spring Expression Language.
SpEL API:-
The SpEL API provides many interfaces and classes. They are as follows:
1 Expression interface
2 SpelExpression class
3 ExpressionParser interface
4 SpelExpressionParser class
5 EvaluationContext interface
6 StandardEvaluationContext class
Feature of SpEL:-
The expression language supports the following functionality
1 Literal expressions
2 Boolean and relational operators
3 Regular expressions
4 Class expressions
5 Accessing properties, arrays, lists, maps
6 Method invocation
7 Relational operators
8 Assignment
9 Calling constructors
10 Bean references
11 Array construction
12 Inline lists
13 Ternary operator
14 Variables
15 User defined functions
16 Collection projection
17 Collection selection
18 Templated expressions
SPEL Example:-
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Demo {
public static void main(String[] args) {
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("'Hello SPEL'");
String message = (String) exp.getValue();
System.out.println(message);
} }