Spring 3.1 – What’s Up and Coming

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(“development”)
public class MyClass() { ... }
<beans profile=“development” … />
#{environment[‘prop.key’]}
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.

<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
<cache:annotation-driven> //referencing "cacheManager"
@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/>
<mvc:annotation-driven>
  <mvc:custom-web-argument-resolvers>
    <bean class="org.example.MyWebArgumentResolver"/>
  </mvc:custom-web-argument-resolvers>
</mvc:annotation-driven>
<mvc:annotation-driven>
  <mvc:message-converters>
    <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
    <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
  </mvc:message-converters>
</mvc:annotation-driven>
<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

Summary

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.

About Gordon

Technology enthusiast primarily focused on Java and Open Source projects. Spring Certified Professional and Trainer. http://twitter.com/gdickens http://linkedin.com/in/gordondickens http://github.com/gordonad
This entry was posted in Grails, Groovy, Java, REST, Spring, Spring Framework, Spring MVC, Testing, Web Services and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

4 Responses to Spring 3.1 – What’s Up and Coming

  1. Pingback: Spring 3.1 - What's Up and Coming

  2. Where can I learn more about the Groovy Support in 3.1?

  3. admin says:

    I have looked in Jira, source code and via Google and have not found any useful information yet.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>