Beginner’s Guide to Spring Expression Language with Spring Boot

Swathi Prasad
2 min readOct 6, 2019

A guide to use Spring Expression Language with @Value annotation.

Image from Flickr

Spring Expression Language (SpEL) is a powerful expression language, which can be used for querying and manipulating an object graph at runtime. SpEL is available via XML or annotation, is evaluated during the bean creation time.

In this article, we will look at some basic examples of SpEL usage in Spring Boot.

Setting up Spring Boot Application

We will create a simple Spring Boot application and create employee.properties file in the resources directory.

employee.names=Petey Cruiser,Anna Sthesia,Paul Molive,Buck Kinnear
employee.type=contract,fulltime,external
employee.age={one:'26', two : '34', three : '32', four: '25'}

Create a class EmployeeConfig as follows:

package com.techshard.spel;import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource (name = "employeeProperties", value = "employee.properties")
@ConfigurationProperties
public class EmployeeConfig {
}

--

--

Swathi Prasad

Software architect and developer living in Germany. Sharing my opinion and what I learn.