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 ...
随机推荐
- HA配置
主T800 eth0 192.168.2.32备T600 eth1 192.168.2.33安装nginx yum install -y nginx 关闭主备的防火墙iptables.selinux ...
- 1103 Integer Factorization (30)
1103 Integer Factorization (30 分) The K−P factorization of a positive integer N is to write N as t ...
- Unity中嵌入网页插件Embedded Browser2.1.0
背景 最近刚换了工作,新公司不是做手游的,一开始有点抵触,总觉得不是做游戏自己就是跨行了,认为自己不对口,但是慢慢发现在这可以学的东西面很广,所以感觉又到了打怪升级的时候了,老子就在这进阶了. 一进公 ...
- sanic连接mongo
方法一: #没有密码,就是没有用户和用户密码 settings={"MOTOR_URI":"mongodb://127.0.0.1:27017/zzy"} ap ...
- runtime机制
runtime(简称运行时),是一套 纯C(C和汇编写的) 的API.而 OC 就是运行时机制,也就是在运行时候的一些机制,其中最主要的是消息机制. 消息机制原理:对象根据方法编号SEL去映射表查找对 ...
- C#操作Word的+ CKEditor 輸出成Word文件(包含圖案上傳)
C#操作Word 参考博文: C#操作word类文件 https://www.cnblogs.com/walking/p/3571068.html C#中的Office操作专栏(21) http:// ...
- Keil5-建立第一个STM32工程
此致:特别感谢作者Lomo-chen所写的文章给我的帮助,我尝试做了一下,成功了,今天整理一下. 一.建立文件夹: 1.在桌面或其他盘建立一个文件夹,此处名称为Test,用来存放工程程序. 2.在Te ...
- BCZM : 1.16
24点游戏 解法一:穷举法 解法二:分治法
- 41. wait notify 方法
wait() 等待,如果一个线程执行了wait方法,那么该线程就会进去一个以锁对象为标识符的线程池中等待 notity() 唤醒,如果一个线程执行了notity方法,那么就会唤醒以锁对象为标识符的线 ...
- 原生js如何获取某一元素的高度
三种方法: 1.document.getElementById("id").style.height,这种方法的前提是必须之前已经显示的在css中声明过height,才能取得正确的 ...