Gordon Dickens is an instructor, mentor & consultant. Gordon is currently architecting and teaching several official SpringSource courses and actively tweets about open source technology at http://twitter.com/gdickens. Gordon is active within the Spring Framework community focussed on: Spring training, Spring Roo, Spring Integration, Spring Batch and Eclipse Virgo OSGi projects. Gordon is a DZone MVB and is not an employee of DZone and has posted 39 posts at DZone. You can read more from them at their website. View Full User Profile

Spring 3.1 – What’s Up and Coming

02.12.2011
| 18497 views |
  • submit to reddit

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 
@Profile(“development”)
public class MyClass() { ... }
 Profile XML Config
<beans profile=“development” … />
 Propery in SPeL
#{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.

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/>
<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.

 

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

Published at DZone with permission of Gordon Dickens, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Jay Spring replied on Sat, 2011/02/12 - 6:03pm

Regarding profiles, is there a way to build an environment independent war, then somehow "inject" the profiles? While the profiles are a nice addition, the ability to update configuration values without rebuilding the java code would make this near perfect.

Steven Baker replied on Sun, 2011/02/13 - 7:16pm

@Jay, use a property file outside of your war that is referenced by your app's context config.

Jay Spring replied on Sun, 2011/02/13 - 8:27pm in response to: Steven Baker

@Steven I see, though how is the property file deployed? Is there a way to automate the deployment and versioning of the file?

joshua long replied on Mon, 2011/02/14 - 1:05am in response to: Jay Spring

one easy way to achieve this is to use a system variable on the Java command invocation. the Spring context looks for -Dspring.profiles.active=foo,bar to list the profiles that should be activated. In this case, the profiles 'foo', an 'bar' would be activated with that configuration.

Steve Holmes replied on Wed, 2011/07/06 - 5:14pm

Does anyone happen to know if there is going to be a groovy template replacement to velocity or freemarker? If so is it going to be like GSPs in Grails? It seems like there is inconsistent reporting on this feature.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.