user373201 user373201 - 1 year ago 85
Java Question

What are some valid uses for spEL (Spring Expression Language) ?

I was looking at spring expression language and it seems very useful if you are using for configuration xml files. However, the reference docs provide lot of examples that use the following code below:

ExpressionParser parser = new SpelExpressionParser();

String name = parser.parseExpression

When and why would I be using this as I can do all of it using regular java. Am I missing some features or other uses where SpelExpressionParser could be handy? Are there other uses cases for spEL that I'm not aware of?

Answer Source

You can use SpEL as a simplified alternative to Java reflection. It reduces a lot of code for you.
One of the use cases, I had at my work is to flatten a deep object graph to a name-value pair for indexing and lookup purposes.

The object graph can be extended by our customers in which case the additional properties should also be indexed. By using SpEL, the customers only need to write expressions in some properties file and the framework code takes care of extracting the new data.

All the use-cases of Java reflection are also potential use-cases for SpEL with added simplicity and reduced code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download