Benefits to using Spring EL over OGNL?

MetroidFan2002 picture MetroidFan2002 · Jan 11, 2011 · Viewed 8.1k times · Source

I was wondering what exactly moved Spring to use Spring EL over OGNL in its web flow product:

http://static.springsource.org/spring-webflow/docs/2.2.x/reference/htmlsingle/spring-webflow-reference.html#el-language-choices

With OGNL, I can dynamically create simple classes and execute methods, etc, directly through the flow. I know it's not a good practice to do that within actual web page templates (i.e. JSPs), because they are based on presentation, but web flow controls your program's logic and I find the ability to use OGNL effectively there to be very convenient. Plus, you can test the flow to ensure that it works easily.

So, two questions:

  1. Are there any major benefits to using Spring EL over OGNL, especially in the context of Spring Webflow?

  2. Can you create objects using Spring EL?

Answer

skaffman picture skaffman · Jan 11, 2011

Well, the "why" is stated in the SpEL docs:

While there are several other Java expression languages available, OGNL, MVEL, and JBoss EL, to name a few, the Spring Expression Language was created to provide the Spring community with a single well supported expression language that can be used across all the products in the Spring portfolio.

While OGNL has its advantages, and its fans, its functionality is too limited for what was required for Spring 3, and so SpEL was born. And because SpEL became the base expression language for Spring, WebFlow moved to that as a replacement for OGNL.

I haven't had much cause to use SpEL much, though, so I couldn't tell you how to do any particular task.

As to its advantages, I'd say the primary one is that while OGNL is now stagnant, SpEL is a core part of Spring now, and so will be continuously improved and extended. Bluntly put, OGNL is dead (it's maintained now by opensymphony.com, which is hardly a dynamic, active organisation)