Variables and Constructors in SpEL by R4R Team

Variables and Constructors in SpEL:-
Variables can be referenced in the expression using the syntax #variableName. Variables are set using the method setVariable on the StandardEvaluationContext.

Employee emp = new Employee("Vipul Sharma", "Proff");

StandardEvaluationContext context = new StandardEvaluationContext(emp);

context.setVariable("newName", "Rahul Sharma");

parser.parseExpression("Name = #newName").getValue(context);

System.out.println(emp.getName()) // "Rahul Sharma"


Constructors can be invoked using the new operator.

Employee emp = p.parseExpression(

"new org.spring.samples.spel.emp.Employee('Vipul Sharma', 'India')")


//create new emp instance within add method of List


"Members.add(new org.spring.samples.spel.emp.Employee(

'Vipul Sharma', 'India'))").getValue(societyContext);

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!