Over a million developers have joined DZone.

Spring 3.1 – What’s Up and Coming

DZone's Guide to

Spring 3.1 – What’s Up and Coming

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

Spring 3.1.0 M1 is expected to be released on Feb 11, 2011. There are many exciting new features expected for the final release which is scheduled for June 2011.

Environment Profiles

Many times we want separate configuration for different environments such as development, qa, production. Also, we may want to provide different bean configuration for traditional or cloud environments as well.

  • Beans can be configured in XML with the additional “profile” attribute
  • Activate 1..n profiles in code or with java arg -Dspring.profiles.active="dev,qa"
  • ParamName for DispatcherServlet “spring.profiles.active”
  • Integration Tests Class GenericXmlApplicationContext
  • Nested “beans” in other words, <beans/> tag can have other <beans/> tags within allowing multiple bean sets for different profiles in the same config file
  • The variable “environment” is already registered for SpEL
Profile Annotation 
public class MyClass() { ... }
 Profile XML Config
<beans profile=“development” … />
  Propery in SPeL
public String myProp;

The “c” Namespace

Much like the existing “p” namespace, the “c” namespace supports constructor arguments. This has the additional benefit of allowing us to reference the constructor arguments by name.

Constructor Namespace
<bean class=“…” c:age=“35” c:amount=“50000”/>

Cache Abstractions

  • Cache Abstractions will be available – not just EHCache, also for Gemfire, Coherence
  • Package: org.springframework.cache
  • Annotation Package: org.springframework.cache.annotation
  • <cache: &/gt; namespace

Constructor Namespace

<cache:annotation-driven> //referencing "cacheManager"

Cachable Annotations

@Cacheable  //field or method

@Cacheable(condition=“name.length < 10”) //conditional

@CacheEvict // remove field from cache
public void clearMyField() { ... }

Servlet 3.0

  • ServletContainerInitializer – XML Free config (no web.xml)
  • package org.springframework.web.context.support.AnnotationConfigWebApplicationContext
  • Async request processing
  • Standard file upload support

HTTP Session Improvements

  • Share information across multiple browser instances
  • Uses Shared Cookie
  • package org.springframework.web.bind.support.SessionAttributeStore
  • Conversation "scope"
  • Useful for MVC & JSF, Web Flow

Groovy Support

  • Groovy/Grails BeanBuilder inclusion
  • <lang:groovy>
  • Groovy based template files (alternative to Velocity and Freemarker)

Feature Configuration

For Bean @Configuration - To support applications with Java based configuration.

  • package org.springframework.context.annotation
  • Picked up via AnnotationConfigApplicationContext // Standalone application context, accepting annotated classes as input
  • Allows scanning for @Configuration classes
  • @FeatureConfiguration // class level - specify the name of the Spring bean definition
  • @Feature // Method w/i @FeatureConfiguration Class

Customizable @MVC

  • Custom @ExceptionHandler support for @Controller methods
  • Custom @ExceptionHandler support for @RequestBody & @ResponseBody
  • You can write a BeanPostProcessor to change AnnotationMethodHandlerAdapter after construction
  • Auto-detection of custom HttpMessageConverters - for example custom MyMappingJacksonHttpMessageConverter
  • Support for custom message codes resolver with <mvc:annotation-driven/>
<bean class="org.example.MyWebArgumentResolver"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
<mvc:annotation-driven message-codes-resolver="org.example.MyMessageCodesResolver"/>

REST Enhancements

  • Interceptors for RestTemplate
  • ClientHttpRequestInterceptor
  • bufferRequestBody property to the SimpleClientHttpRequestFactory to handle large payloads with RestTemplate
  • New WebRequest.checkNotModified(String) // only had long support previously
  • New @ResponseEntity
  • To support OAuth with ClientHttpRequestInterceptors


Many of the items included here are specific features for 3.1.0.M1, there are many more improvements coming for MVC customization and REST improvements in M2.


From http://gordondickens.com/wordpress/2011/02/11/spring-3-1-whats-up-and-coming/

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}