In Spring EL, you can reference a bean, and nested properties using a ‘dot (.)‘ symbol. For example, “bean.property_name“. public class Customer { @Value("#{addressBean.country}") private String country; In above code snippet, it inject the value of “country” property from “addressBean” bean into current “customer” class, “country” property. Spring EL in Annotation See following example, show […]

Read more Spring EL bean reference example

Spring EL supports regular expression using a simple keyword “matches“, which is really awesome! For examples, @Value("#{‘100’ matches ‘\\d+’ }") private boolean isDigit; It test whether ‘100‘ is a valid digit via regular expression ‘\\d+‘. Spring EL in Annotation See following Spring EL regular expression examples, some mixed with ternary operator, which makes Spring EL […]

Read more Spring EL regular expression example

Spring EL supports ternary operator , perform “if then else” conditional checking. For example, condition ? true : false Spring EL in Annotation Spring EL ternary operator with @Value annotation. In this example, if “itemBean.qtyOnHand” is less than 100, then set “customerBean.warning” to true, else set it to false. package com.mkyong.core; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; […]

Read more Spring EL ternary operator (if-then-else) example

Spring expression language (SpEL) allow developer uses expression to execute method and inject the method returned value into property, or so called “SpEL method invocation“. Spring EL in Annotation See how to do Spring EL method invocation with @Value annotation. package com.mkyong.core; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component("customerBean") public class Customer { @Value("#{‘mkyong’.toUpperCase()}") private String name; […]

Read more Spring EL method invocation example

Spring expression language (SpEL) supports many functionality, and you can test those expression features with this special “ExpressionParser” interface. Here’s two code snippets, show the basic usage of using Spring EL. SpEL to evaluate the literal string expression. ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression("’put spel expression here’"); String msg = exp.getValue(String.class); SpEL […]

Read more Test Spring el with ExpressionParser