Spring Expression Language (SPEL) Tutorial
Last Updated : 31 May 2026
SpEL is an exression language supporting the features of querying and manipulating an object graph at runtime.
There are many expression languages available such as JSP EL, OGNL, MVEL and JBoss EL. SpEL provides some additional features such as method invocation and string templating functionality.
SpEL API
The Spring Expression Language (SpEL) API provides several interfaces and classes that are used to parse, evaluate, and manipulate expressions at runtime.
- Expression Interface: The Expression interface represents a parsed expression. It provides methods to evaluate expressions and retrieve their values.
- SpelExpression Class: The SpelExpression class is the implementation of the Expression interface. It stores the parsed expression and performs the actual evaluation.
- ExpressionParser Interface: The ExpressionParser interface is used to parse expression strings into executable expression objects. It serves as the entry point for working with SpEL expressions.
- SpelExpressionParser Class: The SpelExpressionParser class is the standard implementation of the ExpressionParser interface. It parses expression strings and creates Expression objects.
- EvaluationContext Interface: The EvaluationContext interface provides the context in which an expression is evaluated. It allows access to variables, methods, and properties during expression evaluation.
- StandardEvaluationContext Class: The StandardEvaluationContext class is a commonly used implementation of the EvaluationContext interface. It provides support for variables, method invocation, property access, and other advanced SpEL features.
SPEL Example: Displaying a Simple String (Hello SEPL)
In this example, we are using a SpEL expression to create and evaluate a simple string value, which is then displayed on the console.
Other SPEL Example
Let's see a lot of useful examples of SPEL. Here, we are assuming all the examples have been written inside the main() method.
Example: Using concat() Method with String
In this example, we are using the concat() method in a SpEL expression to combine two strings and generate a new string value.
Example: Converting a String into a Byte Array
In this example, we are converting a string into its corresponding byte array representation using a SpEL expression.
Example: Getting the Length of a Byte Array
In this example, we are retrieving the total number of bytes generated after converting a string into a byte array.
Example: Converting a String to Uppercase
In this example, we are using a SpEL expression to invoke the toUpperCase() method and convert all characters of a string into uppercase letters.