posts - 64,comments - 22,trackbacks - 0
如果不配置其他参数,大致相当于以下的配置文件(参考自org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser) 
  1 <!-- 配置路径扩展名映射的媒体类型 -->
  2   <bean name="pathExtensionContentNegotiationStrategy"
  3         class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
  4     <constructor-arg>
  5       <props>
  6         <!-- if romePresent -->
  7         <prop key="atom">application/atom+xml</prop>
  8         <prop key="rss">application/rss+xml</prop>
  9         <!-- endif -->
 10         <!-- if jackson2Present || jacksonPresent -->
 11         <prop key="json">application/json</prop>
 12         <!-- endif -->
 13         <!-- if jaxb2Present -->
 14         <prop key="xml">application/xml</prop>
 15         <!-- endif -->
 16       </props>
 17     </constructor-arg>
 18   </bean>
 19 
 20   <!-- 配置映射媒体类型的策略 -->
 21   <bean name="mvcContentNegotiationManager"
 22         class="org.springframework.web.accept.ContentNegotiationManager">
 23     <constructor-arg>
 24       <list>
 25         <ref bean="pathExtensionContentNegotiationStrategy" />
 26       </list>
 27     </constructor-arg>
 28   </bean>
 29 
 30   <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
 31     <property name="order" value="0"/>
 32     <property name="removeSemicolonContent" value="false"/>
 33     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager"/>
 34   </bean>
 35 
 36   <!-- 配置数据转换服务,默认使用格式化数据转换服务,可以对日期和数字进行格式化 -->
 37   <bean name="conversionService"
 38         class="org.springframework.format.support.DefaultFormattingConversionService">
 39     <constructor-arg index="0">
 40       <null/>
 41     </constructor-arg>
 42     <constructor-arg index="1" value="true"/>
 43   </bean>
 44 
 45   <bean name="validator"
 46         class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
 47 
 48   <!-- 配置数据绑定,通过转换服务实现绑定,如果包含jsr303实现还将进行校验 -->
 49   <bean name="webBindingInitializer"
 50         class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
 51     <property name="conversionService" ref="conversionService" />
 52     <!-- if jsr303Present -->
 53     <property name="validator" ref="validator" />
 54     <!-- endif -->
 55   </bean>
 56 
 57   <bean name="byteArrayHttpMessageConverter"
 58         class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
 59 
 60   <bean name="stringHttpMessageConverter"
 61         class="org.springframework.http.converter.StringHttpMessageConverter">
 62     <property name="writeAcceptCharset" value="false" />
 63   </bean>
 64 
 65   <bean name="resourceHttpMessageConverter"
 66         class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
 67   <bean name="sourceHttpMessageConverter"
 68         class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
 69   <bean name="allEncompassingFormHttpMessageConverter"
 70         class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
 71   <bean name="atomFeedHttpMessageConverter"
 72         class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter"/>
 73   <bean name="rssChannelHttpMessageConverter"
 74         class="org.springframework.http.converter.feed.RssChannelHttpMessageConverter"/>
 75   <bean name="jaxb2RootElementHttpMessageConverter"
 76         class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
 77   <bean name="mappingJacksonHttpMessageConverter"
 78         class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
 79 
 80   <!-- 配置@RequestBody,@ResponseBody注解可用的转换器 -->
 81   <util:list id="messageConverters"
 82              list-class="org.springframework.beans.factory.support.ManagedList">
 83     <ref bean="byteArrayHttpMessageConverter" />
 84     <ref bean="stringHttpMessageConverter" />
 85     <ref bean="resourceHttpMessageConverter" />
 86     <ref bean="sourceHttpMessageConverter" />
 87     <ref bean="allEncompassingFormHttpMessageConverter" />
 88     <!-- if romePresent -->
 89     <ref bean="atomFeedHttpMessageConverter" />
 90     <ref bean="rssChannelHttpMessageConverter" />
 91     <!-- endif -->
 92     <!-- if jaxb2Present -->
 93     <ref bean="jaxb2RootElementHttpMessageConverter" />
 94     <!-- endif -->
 95     <!-- if jacksonPresent -->
 96     <ref bean="mappingJacksonHttpMessageConverter" />
 97     <!-- endif -->
 98   </util:list>
 99 
100   <!-- 将任意类型的Controller适配为Handler -->
101   <bean name="requestMappingHandlerAdapter"
102         class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
103     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
104     <property name="webBindingInitializer" ref="webBindingInitializer" />
105     <property name="messageConverters" ref="messageConverters" />
106   </bean>
107 
108   <!-- 这个拦截器暴露转换器服务让spring:bind和spring:eval标签可用 -->
109   <bean name="csInterceptor"
110         class="org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor">
111     <constructor-arg index="0" ref="conversionService"/>
112   </bean>
113 
114   <!-- 现在所有拦截器都必须设定响应的路径映射 -->
115   <bean name="mappedCsInterceptor"
116         class="org.springframework.web.servlet.handler.MappedInterceptor">
117     <constructor-arg index="0">
118       <null/>
119     </constructor-arg>
120     <constructor-arg index="1" ref="csInterceptor"/>
121   </bean>
122 
123   <!-- 使用@ExceptionHandler注解的方法来处理Exception,优先级为0(最高) -->
124   <bean name="exceptionHandlerExceptionResolver"
125         class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
126     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
127     <property name="messageConverters" ref="messageConverters" />
128     <property name="order" value="0" />
129   </bean>
130 
131   <!-- 如果抛出的Exception类带有@ResponseStatus注解,响应返回该注解的Http状态码,优先级为1 -->
132   <bean name="responseStatusExceptionResolver"
133         class="org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver">
134     <property name="order" value="1" />
135   </bean>
136 
137   <!-- SpringMvc内部异常处理 -->
138   <bean name="defaultExceptionResolver"
139         class="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver">
140     <property name="order" value="2" />
141   </bean>
142 
posted on 2014-08-03 22:35 hellxoul 阅读(2885) 评论(1)  编辑  收藏 所属分类: spring mvc

FeedBack:
# re: 研究SpringMvc 3.2的默认干了什么
2015-06-19 10:06 | zuidaima
spring mvc demo教程源代码下载 :http://zuidaima.com/share/kspringmvc-p1-s1.htm  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: