BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Spring 3.0: Java 5 Required, Adds New Expression Language and REST Support

Spring 3.0: Java 5 Required, Adds New Expression Language and REST Support

This item in japanese

Bookmarks

A new version of the Spring Framework, version 3.0, was released today. InfoQ spoke with Juergen Hoeller, technical lead of the Spring Framework project, to learn more about this release and the changes that it brings to the Spring portfolio.

Hoeller indicated that the major new features which are present in Spring 3.0 are:

  • Java 5 required - The core APIs have been updated to use Java 5 features such as generics and annotations, and Spring 3.0 now requires Java 5 or later
  • Spring Expression Language (SpEL) - Similar to the Unified EL found in JSF, construction of rich expressions is now greatly simplified
  • Extended support for annotation-based components - Some of the Spring JavaConfig capabilities have been migrated into the core framework, such as @Configuration, @Bean and @DependsOn
  • Declarative model validation using constraint annotations - JSR 303 support has been added, and validation rules can now be added to beans using annotations such as @NotNull and @Max(23)
  • Comprehensive REST support in Spring MVC - Support for building RESTful servers and clients has been added
  • Java EE 6 support - Many of the Java EE 6 features such as JPA 2.0 and JSF 2.0 are supported, and they work on non-EE 6 containers like Tomcat and J2EE 1.4 app servers
  • JSR 330 support - The javax.inject annnotations introduced by JSR 330 are now supported
  • Annotation-based formatting - Bean fields can be automatically formatted and converted using annotations such as @DateFimeFormat(iso=ISO.DATE) and @NumberFormat(style=Style.CURRENCY)

A comprehensive changelog and reference documentation are also available.

Hoeller touched upon SpEL in a bit more detail:

SpEL is a rich expression language that syntactically follows Unified EL, quite similar to the use of expressions in JSF. We have our own expression parser with special capabilities that we are taking advantage of: for use in bean definition configuration but also for use in projects like Spring Integration. In Spring core, "#{...}" expressions may be used in many places such as XML bean definitions and @Value annotations, dynamically referring to other beans by name and dereferencing their properties in a concise fashion.

For example, the following XML block (from the 3.0 documentation) uses SpEL to configure the properties of a Spring bean by reading from the JVM's System properties:

<bean class="mycompany.RewardsTestDatabase">
    <property name="databaseName"
        value="#{systemProperties.databaseName}"/>

    <property name="keyGenerator"
        value="#{strategyBean.databaseKeyGenerator}"/>
</bean>

The new REST support was also explained a bit:

Our challenge was to bring REST support to the world of Spring MVC, putting powerful new functionality into the hands of MVC users. We decided that native MVC support for path variable extraction, content negotiation etc was the right way to go here - considering Spring MVC's strengths and taking them to the next level, without breaking the fundamental architecture. This worked out well and makes it straightforward for existing Spring MVC applications to adopt REST features too.

Our primary focus is on web user interfaces following REST conventions. Next to that, there is also an increasing interest in REST-based web services on a Spring MVC basis, in particular in combination with the OXM (Object/XML Mapping) module that became part of the Spring core now. Finally, we are providing client-side support in the form of a Spring-style RestTemplate class, for interacting with a REST-oriented backend server programmatically.

For those who are on Spring 2.5 and who have updated their code to follow the annotation-based style which was adopted in that release, the upgrade path should be a smooth one - new features may be used selectively after upgrading to 3.0, and no fundamental architectural changes are needed. For those who are using older variants such as the form controller class hierarcy, these are still supported in 3.0 but are now deprecated. To use new 3.0 features, a move to the annotation-based @MVC style is required. For Spring 2.0 users, 99% of the code should continue to work, however older components such as Apache Commons Attributes, WebLogic 8.1 and WebSphere 5.1 support have been removed.

When asked about future plans for the Spring Framework, Hoeller said that development will continue to be heavily influenced by the other projects in the Spring portfolio, such as Spring Integration, Spring Web Flow, SpringSource dm Server and Spring Roo. For the 3.1 release, the feature set will be heavily influenced by Spring Integration 2.0 and Spring Web Flow 3.0 with capabilities such as first-class conversation management, extended support for scopes, and refinement of the annotation-based component model being planned. After the planned release of 3.1 in mid 2010 there will be a follow-on 3.2 release, but the specific plans for 3.2 have not yet been finalized.

Rate this Article

Adoption
Style

BT