Skip to main content
Chapter 3 of 18 · 1 sections

Spring: Expression Language (SpEL)

Read expression syntax for literals, collections, maps, and method calls in Spring configuration.

Original chapter: Spring Expression Language (SpEL). The text and examples below are preserved from the historical source; read the corrections above before using them.

Section 3.1: Syntax Reference

You can use @Value("#{expression}") to inject value at runtime, in which the expression is a SpEL expression.

Literal expressions

Supported types include strings, dates, numeric values (int, real, and hex), boolean and null.

Source example · PDF page 15
"#{'Hello World'}"  //strings
"#{3.1415926}"      //numeric values (double)
"#{true}"           //boolean
"#{null}"           //null

Inline list

Source example · PDF page 15
"#{1,2,3,4}"              //list of number
"#{{'a','b'},{'x','y'}}"  //list of list

Inline Maps

Source example · PDF page 15
"#{name:'Nikola',dob:'10-July-1856'}"
"#{name:{first:'Nikola',last:'Tesla'},dob:{day:10,month:'July',year:1856}}" //map of maps

Invoking Methods

Source example · PDF page 15
"#{'abc'.length()}"      //evaluates to 3
"#{f('hello')}"   //f is a method in the class to which this expression belongs, it has a string
parameter
Buy me a coffee
Daily Practice
0/0