Spring - Expression Language (SpEL) Last Updated : 04 Oct, 2025 Comments Improve Suggest changes 64 Likes Like Report Spring Expression Language (SpEL) is a powerful expression language provided by the Spring Framework that allows developers to query and manipulate objects at runtime. SpEL can be used for configuring beans, evaluating expressions dynamically, and accessing properties or methods in Spring applications.SpEL SyntaxSpEL expressions are enclosed in ${} or #{}.#{}: Used for evaluating expressions dynamically in Spring bean definitions.${}: Used for property placeholders (externalized configuration).Key Features of SpELProperty Access: Access object properties using a simple syntax.Method Invocation: Call methods on beans or objects dynamically.Arithmetic Operations: Perform calculations like addition, subtraction, multiplication, and division.Logical and Relational Operators: Evaluate boolean expressions using ==, >, <, &&, ||.Collection Support: Access arrays, lists, maps, and sets.Bean References: Reference Spring beans by their ID.Ternary Operator: Use ? : for conditional expressions.Regular Expression Matching: Supports matches for pattern matching.Basic Usage in Spring XML XML <bean id="exampleBean" class="com.example.Person"> <property name="age" value="#{30 + 5}" /> <property name="name" value="#{'John Doe'}" /> </bean> Explanation:#{30 + 5} evaluates to 35 and sets the age property.#{'John Doe'} sets the name property.Using SpEL with Annotations Java import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class Employee { @Value("#{10 * 2}") // Arithmetic operation private int salary; @Value("#{'John'.toUpperCase()}") // Method invocation private String name; public int getSalary() { return salary; } public String getName() { return name; } } Explanation:SpEL evaluates 10 * 2 to 20 and assigns it to salary.The toUpperCase() method converts "John" to "JOHN".Accessing Beans in SpEL Java @Component("myBean") public class MyBean { private String value = "Spring SpEL"; public String getValue() { return value; } } Java @Component public class Demo { @Value("#{myBean.value}") // Access property of another bean private String val; } Explanation:#{myBean.value} references the value property of the bean with ID myBean.SpEL OperatorsOperatorDescriptionExample+Addition / Concatenation#{2 + 3} → 5-Subtraction#{10 - 4} → 6*Multiplication#{5 * 2} → 10/Division#{10 / 2} → 5%Modulus#{10 % 3} → 1==Equals#{5 == 5} → true!=Not equals#{5 != 2} → true>Greater than#{10 > 5} → true<Less than#{3 < 7} → trueand / &&Logical AND#{true and false} → false`or /`!Logical NOT#{!true} → false?:Ternary#{1 > 0 ? 'Yes' : 'No'} → "Yes"Working with Collections Java @Value("#{{1, 2, 3, 4}.?[#this > 2]}") // Selection private List<Integer> filteredList; @Value("#{{'a':'A', 'b':'B'}}") // Map initialization private Map<String, String> map; Projection (!): Transforms each element.Selection (.?): Filters elements based on a condition.Programmatic Evaluation of SpEL Java import org.springframework.expression.ExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.Expression; public class SpELProgrammatic { public static void main(String[] args) { ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression("'Hello World'.concat('!!!')"); String message = exp.getValue(String.class); System.out.println(message); } } Output:Hello World!!!Advantages of Using SpELEnables dynamic bean configuration without hardcoding values.Simplifies access to bean properties and methods in a declarative manner.Supports complex expressions, including collections, maps, ternary operations, and regular expressions.Integrates with Spring annotations and XML configuration seamlessly.Allows runtime evaluation for programmatic scenarios. Create Quiz Comment S sanketnagare Follow 64 Improve S sanketnagare Follow 64 Improve Article Tags : Springboot Geeks-Premier-League-2022 Java-Spring Explore Spring Boot Basics and PrerequisitesIntroduction to Spring Boot4 min readDifference between Spring and Spring Boot4 min readSpring - Understanding Inversion of Control with Example6 min readSpring - IoC Container2 min readBeanFactory vs ApplicationContext in Spring6 min readSpring Boot CoreSpring Boot - Architecture2 min readSpring Boot - Annotations5 min readSpring Boot Actuator5 min readHow to create a basic application in Java Spring Boot3 min readSpring Boot - Code Structure3 min readSpring Boot - Scheduling4 min readSpring Boot - Logging8 min readException Handling in Spring Boot8 min readSpring Boot with REST APISpring Boot - Introduction to RESTful Web Services3 min readSpring Boot - REST Example4 min readHow to Create a REST API using Java Spring Boot?4 min readHow to Make a Simple RestController in Spring Boot?2 min readJSON using Jackson in REST API Implementation with Spring Boot3 min readSpring Boot with Database and Data JPA Spring Boot with H2 Database6 min readSpring Boot - JDBC8 min readAdvantages of Spring Boot JDBC3 min readSpring Boot - CRUD Operations7 min readSpring Boot - MongoRepository with Example5 min readSpring Boot JpaRepository with Example5 min readSpring Boot - CrudRepository with Example5 min readSpring Boot with KafkaSpring Boot Kafka Producer Example3 min readSpring Boot Kafka Consumer Example3 min readSpring Boot | How to consume JSON messages using Apache Kafka3 min readSpring Boot | How to consume string messages using Apache Kafka3 min readSpring Boot | How to publish String messages on Apache Kafka2 min readSpring Boot | How to publish JSON messages on Apache Kafka4 min readSpring Boot with AOPSpring Boot - AOP(Aspect Oriented Programming)4 min readHow to Implement AOP in Spring Boot Application4 min readSpring Boot - Difference Between AOP and OOP3 min readSpring Boot - Difference Between AOP and AspectJ3 min readSpring Boot - Cache Provider6 min read Like