spring MVC <mvc:annotation-driven>
<!-- 配置路径扩展名映射的媒体类型 -->
<bean name="pathExtensionContentNegotiationStrategy"
class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
<props>
<!-- if romePresent -->
<prop key="atom">application/atom+xml</prop>
<prop key="rss">application/rss+xml</prop>
<!-- endif -->
<!-- if jackson2Present || jacksonPresent -->
<prop key="json">application/json</prop>
<!-- endif -->
<!-- if jaxb2Present -->
<prop key="xml">application/xml</prop>
<!-- endif -->
</props>
</constructor-arg>
</bean> <!-- 配置映射媒体类型的策略 -->
<bean name="mvcContentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
<list>
<ref bean="pathExtensionContentNegotiationStrategy" />
</list>
</constructor-arg>
</bean> <!-- 配置方法级别的@RequestMapping处理器 -->
<bean name="requestMappingHandlerMapping"
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="order" value="0" />
<property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
</bean> <!-- 配置数据转换服务,默认使用格式化数据转换服务,可以对日期和数字进行格式化 -->
<bean name="conversionService"
class="org.springframework.format.support.DefaultFormattingConversionService">
<constructor-arg index="0">
<null></null>
</constructor-arg>
<constructor-arg index="1">
<value>true</value>
</constructor-arg>
</bean> <bean name="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"></bean> <!-- 配置数据绑定,通过转换服务实现绑定,如果包含jsr303实现还将进行校验 -->
<bean name="webBindingInitializer"
class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService" ref="conversionService" />
<!-- if jsr303Present -->
<property name="validator" ref="validator" />
<!-- endif -->
</bean> <bean name="byteArrayHttpMessageConverter"
class="org.springframework.http.converter.ByteArrayHttpMessageConverter"></bean>
<bean name="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="writeAcceptCharset" value="false" />
</bean>
<bean name="resourceHttpMessageConverter"
class="org.springframework.http.converter.ResourceHttpMessageConverter"></bean>
<bean name="sourceHttpMessageConverter"
class="org.springframework.http.converter.xml.SourceHttpMessageConverter"></bean>
<bean name="allEncompassingFormHttpMessageConverter"
class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"></bean>
<bean name="atomFeedHttpMessageConverter"
class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter"></bean>
<bean name="rssChannelHttpMessageConverter"
class="org.springframework.http.converter.feed.RssChannelHttpMessageConverter"></bean>
<bean name="jaxb2RootElementHttpMessageConverter"
class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"></bean>
<bean name="mappingJackson2HttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
<bean name="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean> <!-- 配置@RequestBody,@ResponseBody注解可用的转换器 -->
<util:list id="messageConverters"
list-class="org.springframework.beans.factory.support.ManagedList.ManagedList">
<ref bean="byteArrayHttpMessageConverter" />
<ref bean="stringHttpMessageConverter" />
<ref bean="resourceHttpMessageConverter" />
<ref bean="sourceHttpMessageConverter" />
<ref bean="allEncompassingFormHttpMessageConverter" />
<!-- if romePresent -->
<ref bean="atomFeedHttpMessageConverter" />
<ref bean="rssChannelHttpMessageConverter" />
<!-- endif -->
<!-- if jaxb2Present -->
<ref bean="jaxb2RootElementHttpMessageConverter" />
<!-- endif -->
<!-- if jackson2Present -->
<ref bean="mappingJackson2HttpMessageConverter" />
<!-- endif -->
<!-- if jacksonPresent -->
<ref bean="mappingJacksonHttpMessageConverter" />
<!-- endif -->
</util:list> <!-- 将任意类型的Controller适配为Handler -->
<bean name="requestMappingHandlerAdapter"
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
<property name="webBindingInitializer" ref="webBindingInitializer" />
<property name="messageConverters" ref="messageConverters" />
</bean> <!-- 这个拦截器暴露转换器服务让spring:bind和spring:eval标签可用 -->
<bean name="csInterceptor"
class="org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor">
<constructor-arg index="0">
<ref bean="conversionService" />
</constructor-arg>
</bean> <!-- 现在所有拦截器都必须设定响应的路径映射 -->
<bean name="mappedCsInterceptor"
class="org.springframework.web.servlet.handler.MappedInterceptor">
<constructor-arg index="0">
<null></null>
</constructor-arg>
<constructor-arg index="1">
<ref bean="csInterceptor" />
</constructor-arg>
</bean> <!-- 使用@ExceptionHandler注解的方法来处理Exception,优先级为0(最高) -->
<bean name="exceptionHandlerExceptionResolver"
class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
<property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
<property name="messageConverters" ref="messageConverters" />
<property name="order" value="0" />
</bean> <!-- 如果抛出的Exception类带有@ResponseStatus注解,响应返回该注解的Http状态码,优先级为1 -->
<bean name="responseStatusExceptionResolver"
class="org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver">
<property name="order" value="1" />
</bean> <!-- SpringMvc内部异常处理 -->
<bean name="defaultExceptionResolver"
class="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver">
<property name="order" value="2" />
</bean>
spring MVC <mvc:annotation-driven>的更多相关文章
- Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->Spring Framework中的spring web MVC模块
spring framework中的spring web MVC模块 1.概述 spring web mvc是spring框架中的一个模块 spring web mvc实现了web的MVC架构模式,可 ...
- spring 3 mvc hello world + mavern +jetty
Spring 3 MVC hello world example By mkyong | August 2, 2011 | Updated : June 15, 2015 In this tutori ...
- Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
之前有一篇<5分钟构建spring web mvc REST风格HelloWorld>介绍了普通方式开发spring web mvc web service.接下来看看使用spring b ...
- Gradle – Spring 4 MVC Hello World Example
In this tutorial, we will show you a Gradle + Spring 4 MVC, Hello World Example (JSP view), XML conf ...
- Spring 3 MVC: Themes In Spring-Tutorial With Example---reference
Welcome to Part 6 of Spring 3.0 MVC Series. In previous article we saw how to add Internationalizati ...
- [转]Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
Spring Boot——2分钟构建spring web mvc REST风格HelloWorld http://projects.spring.io/spring-boot/ http://spri ...
- Spring 4 MVC+Hibernate 4+MySQL+Maven使用注解集成实例
Spring 4 MVC+Hibernate 4+MySQL+Maven使用注解集成实例 转自:通过注解的方式集成Spring 4 MVC+Hibernate 4+MySQL+Maven,开发项目样例 ...
- Spring Web MVC(三)之注解
[toc] spring web mvc 基于注解的优化 我写的注解是按照spring web的部件分类写的,这样的话比较方便查看,大家感觉有用的话可以分享个别人,希望对对更多的人有帮助.毕竟零基础开 ...
- Spring 4 MVC example with Maven
In this tutorial, we show you a Spring 4 MVC example, using Maven build tool. Technologies used : Sp ...
- Spring 4 MVC example with Maven - [Source Code Download]
In this tutorial, we show you a Spring 4 MVC example, using Maven build tool. Technologies used : Sp ...
随机推荐
- adis16405 配置
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- Junit用断言对控制台输出进行测试
核心思路: 在测试前,将标准输出定向到ByteArrayOutputStream中去 用输出流文件断言内容 测试完成,将标准输出修改为console 具体操作示例 基本通用复制粘贴操作 public ...
- 【Java多线程系列一】Java实现线程方法
Java实现线程的两种方法 继承Thread类 实现Runnable接口 它们之间的区别如下: Java的类为单继承,但可以实现多个接口,因此Runnable可能在某些场景比Thread更适用 Thr ...
- vue-router 动态路由
上一篇文章我们已经配置好了路由,下面,来说说如何实现动态路由. 比如,我想在 news 页点击列表项,跳转到对应项,如图所示: 这里引用的数据是豆瓣电影,地址: http://api.douban.c ...
- xshell6 远程连接时提示 WARNING! The remote SSH server rejected X11 forwarding request.
1.输入命令 vi /etc/ssh/sshd_config ,修改配置文件 2.将UserLogin no 的注释解除 3.执行yum install -y xorg-x11-font xorg ...
- 11-Ubuntu-根目录下各目录的功能详细介绍
转自: https://www.cnblogs.com/yudar/p/5809219.html 注:总结的非常详细
- Mac OS X终端的常用操作命令(UNIX指令)
用了十多年windows,终于换了个高配Mac,俗话说 无论前端还是后端最终还是走向了linux,无论是换了多少台PC最终都会走向Mac.不学习命令行用什么Mac? 干就完了~ pwd 显示现在的文件 ...
- transport error 202: bind failed: Address already in use
background: I have terminated some test debugger without properly saying goodbye. the JDWP didn't cl ...
- Vue之获取用户当前所在省市
今天小编给大家带来的是使用Vue获取用户所在城市,Vue是很强大的,给大家准备好现成的插件供大家调用,下面的Demo小编使用的是百度API. 首先我们从百度平台申请百度地图的秘钥,申请成功后我们将&l ...