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 ...
随机推荐
- 正则表达式Pattern类的基本用法
public void mailRegex() { // 要验证的字符串 String str = "shiruo.hdp@taobao.com"; // 邮箱验证规则 Strin ...
- Openstack组件部署 — Nova overview
目录 目录 前文列表 前言 Compute service overview Nova 的组件 nova-api service nova-api-metadata service nova-comp ...
- SVN工作副本已经锁定错误的解决方法
SVN工作副本锁定错误的解决方法 我们在使用svn版本控制软件时,时常会遇到想要更新本地项目的版本,却突然提示:工作副本已锁定.截图如下: 这种错误让人感觉很不舒服,实际上自己也没做过什么操作就这样了 ...
- python3 递归函数return返回None
今天写了一个函数,执行之后打印出来的结果是None,不明白,之后百度了一下,这里记一下过程,免得之后再踩坑 #!/usr/bin/python3# -*- coding:utf-8 -*- def b ...
- script标签的defer、async属性
之前一直对script标签的defer.async属性一知半解,直到看到了论坛上某大神发的图片,茅塞顿开!!!!!
- Spring-boot整合Redis,遇到的问题
1.通过set进redis中的数据,get不到 String cityKey ="city_"+id; ValueOperations<String,City> ope ...
- tomcat启动内存修改
# USE_NOHUP (Optional) If set to the string true the start command will # ...
- MYSQL分数排名
编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同.请注意,平分后的下一个名次应该是下一个连续的整数值.换句话说,名次之间不应该有“间隔”. +----+----- ...
- msql数据库基础
一.数据库操作 1.显示数据库 SHOW DATABASES; SHOW CREATE DATABASE 数据库名称; #数据库的创建信息 2.创建数据库 #utf8 CREATE DATABASE ...
- Qt 【无法打开 xxxx头文件】
经过多次磕碰,终于发现了通用的办法. 测试环境Qt5.5.1 mvcs 比如需要用到QtWin 直接去包含然后运行,but fail, 我去查找他的父类 QtWinExtras Qt自带的自动补全, ...