Results 1 to 2 of 2

Thread: What is Spring Expression Language (SpEL) good for?

Hybrid View

  1. #1

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •