> For the complete documentation index, see [llms.txt](https://potoyang.gitbook.io/spring-in-action-v4/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://potoyang.gitbook.io/spring-in-action-v4/1/1.4spring-de-xin-gong-neng/1.4.1spring-3.1-xin-te-xing.md).

# 1.4.1　Spring 3.1 新特性

Spring 3.1 带来了多项有用的新特性和增强，其中有很多都是关于如何简化和改善配置的。除此之外，Spring 3.1 还提供了声明式缓存的支持以及众多针对 Spring MVC 的功能增强。下面的列表展现了 Spring 3.1 重要的功能升级：

* 为了解决各种环境下（如开发、测试和生产）选择不同配置的问题，Spring 3.1 引入了环境 profile 功能。借助于 profile，就能根据应用部署在什么环境之中选择不同的数据源 bean；
* 在 Spring 3.0 基于 Java 的配置之上，Spring 3.1 添加了多个 enable 注解，这样就能使用这个注解启用 Spring 的特定功能；
* 添加了 Spring 对声明式缓存的支持，能够使用简单的注解声明缓存边界和规则，这与你以前声明事务边界很类似；
* 新添加的用于构造器注入的 c 命名空间，它类似于 Spring 2.0 所提供的面向属性的 p 命名空间，p 命名空间用于属性注入，它们都是非常简洁易用的；
* Spring 开始支持 Servlet 3.0，包括在基于 Java 的配置中声明 Servlet 和 Filter，而不再借助于 web.xml；
* 改善 Spring 对 JPA 的支持，使得它能够在 Spring 中完整地配置 JPA，不必再使用persistence.xml 文件。

Spring 3.1 还包含了多项针对 Spring MVC 的功能增强：

* 自动绑定路径变量到模型属性中；
* 提供了 @RequestMapping produces 和 consumes 属性，用于匹配请求中的 Accept 和 Content-Type 头部信息；
* 提供了 @RequestPart 注解，用于将 multipart 请求中的某些部分绑定到处理器的方法参数中；
* 支持 Flash 属性（在 redirect 请求之后依然能够存活的属性）以及用于在请求间存放 flash 属性的 RedirectAttributes 类型。

除了 Spring 3.1 所提供的新功能以外，同等重要的是要注意 Spring 3.1 不再支持的功能。具体来讲，为了支持原生的 EntityManager，Spring 的 JpaTemplate 和 JpaDaoSupport 类被废弃掉了。尽管它们已经被废弃了，但直到 Spring 3.2 版本，它依然是可以使用的。但最好不要再使用它们了，因为它们不会进行更新以支持 JPA 2.0，并且已经在 Spring 4 中移除掉了。

现在，让我们看一下 Spring 3.2 提供了什么新功能。
