Tuesday, October 5, 2010

Spring 3: Spring Expression Language - SpEL

I realized that I have covered most of the major functions in the Spring 3 release, but completely overlooked SpEL. Now even though I am a huge Spring fan, all this functionality does actually scare me a little bit. To often have I seen people hang themselves with awesome, innocent looking ropes just like this one. Soon there will be some project that needs to be "dynamic" and some person/consultant/architect/developer will have this amazing idea and place code somewhere they can edit it externally. Then this SpEL can read this and "dynamically do stuff"...
(I am pretty sure that I have been that "person" somewhere in my career, it all feels horribly familiar.)
And all of that only comes at the price of some poor developers' sanity trying to maintain it. To be fair, this view is purely based on personal experiences and maybe slightly unjustified, but I have seen my share of good ideas gone bad in my time and it feels like SpEL is wide open for misuse.

Putting my concerns aside and refocusing on: it's something new , it's shiny and Spring-made so I obviously can't resist trying it out.
First I go digging for information to answer: "What is SpEL, Spring Expression Language?"
A quick summary of what I find:
It is an expression language that supports querying and manipulating objects at runtime. It can be used as part of the standard configuration, XML or annotation based, but can also be evaluated directly by the application code. It allows you to overcome the limitation of using only fixed values. It can be used for bean definitions in both XML- and annotation-based configurations. There is a facility to access system, environment and context parameters.

I have just covered thing that I would generally need or have run into... there is however quite a bit more information within the Spring documentation

So using Maven first thing I needed was to add following:

Using SpEL in Code:

Below I have examples code of: Setting a value, Calling a constructor, creating variables, calling a static function, all the basic operators, the instanceof operator and even the ternary if.

Using SpEL in XML Config: As with the Java code, here is the same functionality within you Spring application XML.

Using SpEL in Annotations:
And then again will the @Value annotation.


  1. It is high time that Apple updated their Maps system with iOS 11. That way, it can finally step up and pose a tough competition to Google with the help of the new drone’s technology. iOS 11 Beta

    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

  2. Nice information about spring expression language My sincere thanks for sharing this post Please Continue to share this post
    Java Training in Chennai

  3. nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    java training in chennai

  4. Hi, I am a big follower of your blog. Really very informative post you shared here. Keep sharing this type of informative blog. Waiting for your next update. If anyone wants to become a Java professional learn Java Training in Bangalore. Nowadays Java has tons of job opportunities for all professionals.

  5. Excellent post!!! Java is most popular and efficient programming language available in the market today. It helps developers to create stunning desktop/web applications loaded with stunning functionalities.
    Core Java Online Training

  6. Your information about Java is useful for me to know more technical information. If it in terms of Job opportunities, again Java outscore everyone.Anybody want to learn
    Core Java Online Training

  7. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work. Selenium Training in Chennai | Software Testing Training in Chennai

  8. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Best BE | B.Tech Project Center in Chennai | ME | M.Tech Project Center in Chennai | Best IT Project Center in Chennai

  9. Excellent post. Thanks for sharing such nice and useful post, Keep updating.


  10. very interesting post, i am glad to see your post. Thanks for sharing. keep updating.



Popular Posts