Announcement Announcement Module
Collapse
No announcement yet.
What is Spring Expression Language (SpEL) good for? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is Spring Expression Language (SpEL) good for?

    Spring Expression Language (SpEL)

    Code:
    The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. The language syntax is similar to Unified EL but offers additional features, most notably method invocation and basic string templating functionality.
    I read through the entire SpEL chapter but I still fail to see the practical usage of this technology. Would anyone able to elaborate it with an example? Why would we want to build a object graph in runtime?

  • #2
    To be able to do runtime evaluations in a concise form for example. The documentation shows some example:http://static.springsource.org/sprin...new-feature-el

    Code:
    <bean class="mycompany.RewardsTestDatabase">
        <property name="databaseName"
            value="#{systemProperties.databaseName}"/>
        <property name="keyGenerator"
            value="#{strategyBean.databaseKeyGenerator}"/>
    </bean>
    or
    Code:
    @Repository 
    public class RewardsTestDatabase {
        @Value("#{systemProperties.databaseName}")
        public void setDatabaseName(String dbName) { … }
    
        @Value("#{strategyBean.databaseKeyGenerator}")
        public void setKeyGenerator(KeyGenerator kg) { … }
    }
    Consider the amount of Java code and hops that one would have to use otherwise.

    Comment

    Working...
    X