首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

Top 五 enhancements of Spring MVC 3.1

2012-06-27 
Top 5 enhancements of Spring MVC 3.1Top 5 enhancements of Spring MVC 3.1 from http://blog.goyello.c

Top 5 enhancements of Spring MVC 3.1
Top 5 enhancements of Spring MVC 3.1
from http://blog.goyello.com/2011/12/16/enhancements-spring-mvc31/

After many months of development, Spring 3.1 has been finally released. The release is shipped with some exciting features like caching abstraction, bean profiles and container configuration simplifications. However, in this blog post I will describe my top 5 enhancements of Spring MVC 3.1.
1. Flash attributes support

Flash attributes are used to store attributes between requests and  are used mostly in Post/Redirect/Get pattern. Prior to Spring 3.1 some additional (repeatable) steps were required to utilize flash attributes in Spring MVC based applications:
Create or copy FlashMap object to hold flash attributes


In the above example, Spring automatically performs the validation and in case of error MethodArgumentNotValidException is thrown. Optional @ExceptionHandler method may be easily created to add custom behavior for handling this type of exception.

4. Supporting PUT request with form encoded data

The limitation of Servlet implementation is that it does not handle the encoded data of the HTTP PUT request properly. Introduction of the new HttpPutFormContentFilter solves that problem. With Spring 3.1 developing a RESTfull or RESTlike API became much simpler. See my previous post to read more about the usage of HttpPutFormContentFilter in a web application.
5. Java based configuration

The xml configuration of a Spring MVC application may be completely replaced by the Java based configuration. The simplest way to configure a web application is to use the @EnableWebMvc annotation:

Extending from WebMvcConfigurerAdapter is not required, but it allows for the customization of the default Spring MVC configuration. The adapter enables us to register additional components like formatters, converters, custom validators, interceptors etc. This way the custom configuration can be done by Java code only. See my previous post about configuring a Spring MVC application with no xml in a Servlet 3.0 based environment.
Spring MVC 3.1 has a lot to offer

Spring MVC 3.1 brings many enhancements. The features mentioned in this blog post should have a positive impact on the application development with Spring MVC. They are not revolutionary, though. However, when I look at all the Spring features and enhancements shipped within the 3.1 release, I feel that the framework is going in the right direction. The caching abstraction, bean profiles, configuration simplifications and many other core features should allow to develop applications more efficiently.
References:

http://blog.springsource.org/2011/12/13/spring-framework-3-1-goes-ga/
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/new-in-3.1.html
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/

热点排行