Spring 3.1 – What’s Up and Coming
Join the DZone community and get the full member experience.
Join For FreeSpring 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
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.
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>
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/
Opinions expressed by DZone contributors are their own.
Comments