Spring spel hello world example

Spring SpEL:

The SpEL stands for Spring Expression Language. It is a powerful expression language which supports querying and manipulating an object graph at the bean creation time or run time. It is similar to other expression languages like JSP EL, OGNL, MVEL and JBoss EL etc with some additional features like method invocation and basic string templating functionality.

ExpressionParser interface is used to test the expressions.



import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
 * Spring SPEL "Hello World" example.
 * @author javawithease
public class HelloTest {
    public static void main(String args[]){
	 //Create a parser with default settings.
	 ExpressionParser parser = new SpelExpressionParser();  
	 //Parse the expression string and return an Expression object 
	 //which can be used for repeated evaluation. 
	 Expression exp = parser.parseExpression("'Hello World!'"); 
	 //Evaluate this expression and returns the result.
	 String message = (String) exp.getValue();  
	 //Print result.


Hello World!

Download this example.