Skip to content

SpEL Expression Delimiters and Syntax

Spring Expression Language (SpEL) uses specific delimiters and syntax structures to define expressions within Spring configurations. The standard format encloses the expression string within #{ }.^[600-developer__spring__spring-spel.md]

Delimiters

The default delimiter used to identify a SpEL expression is #{ <expression string> }.^[600-developer__spring__spring-spel.md]

These delimiters distinguish SpEL expressions from standard property placeholders, which typically use the ${ <property> } syntax.^[600-developer__spring__spring-spel.md]

Definition Syntax

Expressions are typically defined using the parseExpression method provided by the SpelExpressionParser.^[600-developer__spring__spring-spel.md]

Template Expressions

When parsing, a ParserContext can be used to handle template expressions.^[600-developer__spring__spring-spel.md] This is useful when embedding an expression within a larger string literal.^[600-developer__spring__spring-spel.md]

Usage Contexts

XML Configuration

In Spring XML bean definitions, the expression syntax is placed inside the value attribute of a property.^[600-developer__spring__spring-spel.md]

Annotation Configuration

In Java code, expressions are often used with the @Value annotation, passing the expression string as the annotation's value.^[600-developer__spring__spring-spel.md]

Sources

^[600-developer__spring__spring-spel.md]