---
title: "springmvc中spring匿名相关配置"
author: "jeans123"
date: "2015-05-25T15:59:19Z"
tags: []
categories: ["Web前端"]
slug: "springmvc-spring"
draft: false
lastmod: "2015-05-26T11:52:23Z"
id: 2214052
url: "https://jeansmo.iteye.com/blog/2214052"
---

&lt;!--配置文件常量加载到内存或应用环境中--&gt;  
    &lt;context:property-placeholder location="classpath\*:conf/db.properties" /&gt;  
  或  
    &lt;bean id="propertyConfigurer"           class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;  
        &lt;property name="location"&gt;  
           &lt;list&gt;   
            &lt;value&gt;userinfo.properties&lt;/value&gt;   
           &lt;/list&gt;  
        &lt;/property&gt;  
    &lt;/bean&gt;

&lt;!--注解解析器--&gt;  
     &lt;context:annotation-config/&gt;  
     这样一条配置，他的作用是式地向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、 PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。注册这4个 BeanPostProcessor的作用，就是为了你的系统能够识别相应的注解.  
不过,我们使用注解一般都会配置扫描包路径选项&lt;context:component-scan base-package=”XX.XX”/&gt; 该配置项其实也包含了自动注入上述processor的功能，因此当使用 &lt;context:component-scan/&gt; 后，就可以将 &lt;context:annotation-config/&gt; 移除了。

&lt;!----&gt;  
     &lt;mvc:annotation-driven /&gt;  
&lt;mvc:annotation-driven /&gt; 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。  
并提供了：数据绑定支持，@NumberFormatannotation支持，@DateTimeFormat支持，@Valid支持，读写XML的支持（JAXB），读写JSON的支持（Jackson）。  
后面，我们处理响应ajax请求时，就使用到了对json的支持。  
后面，对action写JUnit单元测试时，要从spring IOC容器中取DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean，来完成测试，取的时候要知道是&lt;mvc:annotation-driven /&gt;这一句注册的这两个bean。

在spring mvc 3.1中，对应变更为  
DefaultAnnotationHandlerMapping -&gt; RequestMappingHandlerMapping  
AnnotationMethodHandlerAdapter -&gt; RequestMappingHandlerAdapter  
AnnotationMethodHandlerExceptionResolver -&gt; ExceptionHandlerExceptionResolver  
[  
扩展:  
&lt;mvc:annotation-driven conversion-service="conversionService" /&gt;   
]