class RootObject {
private String prop;
private Child child;
}
// with root object
JavaExpressionParser expressionParser = new SpelExpressionParser();
Expression expression = expressionParser.parseExpression("prop + #var + 'somethingelse'");
RootObject rootObject = new RootObject("whatever");
EvaluationContext context = new StandardEvaluationContext(rootObject);
context.setVariable("var", "var val");
String result = expression.getValue(context, String.class);
@Value("#{...}")
- Basic format for property binding in Spring, which comes fromStandardBeanExpressionResolver
which hasexpressionPrefix
as#{
& sufix as}
T(fqcn.MyClass).staticMethod(..)
- For accessing javaClass
object@myBeanRef.prop
- For accessing beans from application context if context is configured with a customBeanResolver
viacontext.setBeanResolver(new MyBeanResolver());
#0
,#methodParam
,#customVar
- Variables set viacontext.setVariable("0", "val")
format can be accessed using#
withinchild.prop")
- Accessing child ofrootObject
set within evaluation contextobj?.nullableProp?.deeperNullableProp")
- Null safe navigationbooleanVar ?: 'Hello'")
- Elvis operator supportedcollection[1]")
- Index based collection element accessmap['key']")
- Access map value based on Keyobj.method('val')")
- Method execution against the childmethodOnRoot('val')")
- Method execution against root object${custom.property}")
- Access environment properties in spring