Skip to content

Instantly share code, notes, and snippets.

@wdahlenburg
Created February 22, 2022 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdahlenburg/b23ea56cdefc1386323fbb2bdf40b7bc to your computer and use it in GitHub Desktop.
Save wdahlenburg/b23ea56cdefc1386323fbb2bdf40b7bc to your computer and use it in GitHub Desktop.
static Object getValue(SpelExpressionParser parser, BeanFactory beanFactory, String entryValue) {
Object value;
String rawValue = entryValue;
if (rawValue != null) {
rawValue = rawValue.trim();
}
if (rawValue != null && rawValue.startsWith("#{") && entryValue.endsWith("}")) {
// assume it's spel
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
Expression expression = parser.parseExpression(entryValue, new TemplateParserContext());
value = expression.getValue(context);
}
else {
value = entryValue;
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment