<mvc:annotation-driven/>浅析

在Spring中这是一个很简洁的标签。它是对两个bean的简写。

在3.0中是  DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter  ,从3.1开始改成了 RequestMappingHandlerMapping 和 RequestMappingHandlerAdapter

其中,Adapter中注入了一个MessageConverter列表,该列表中又注入了几个经常用到的格式转换,比如XmlHttpMessageConverter/JsonHttpMessageConverter等,详见下面贴来的Spring 3.0.X:

 1 <!-- 注解请求映射  -->
 2     <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
 3         <property name="interceptors">
 4             <list>
 5                 <ref bean="logNDCInteceptor"/>   <!-- 日志拦截器,这是你自定义的拦截器 -->
 6             </list>
 7         </property>
 8     </bean>
 9     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
10         <property name="messageConverters">
11             <list>
12                 <ref bean="byteArray_hmc" />
13                 <ref bean="string_hmc" />
14                 <ref bean="resource_hmc" />
15                 <ref bean="source_hmc" />
16                 <ref bean="xmlAwareForm_hmc" />
17                 <ref bean="jaxb2RootElement_hmc" />
18                 <ref bean="jackson_hmc" />
19             </list>
20         </property>
21     </bean>
22     <bean id="byteArray_hmc" class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /><!-- 处理.. -->
23     <bean id="string_hmc" class="org.springframework.http.converter.StringHttpMessageConverter" /><!-- 处理.. -->
24     <bean id="resource_hmc" class="org.springframework.http.converter.ResourceHttpMessageConverter" /><!-- 处理.. -->
25     <bean id="source_hmc" class="org.springframework.http.converter.xml.SourceHttpMessageConverter" /><!-- 处理.. -->
26     <bean id="xmlAwareForm_hmc" class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /><!-- 处理.. -->
27     <bean id="jaxb2RootElement_hmc" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" /><!-- 处理.. -->
28     <bean id="jackson_hmc" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /><!-- 处理json-->

时间: 2024-11-12 09:12:21

<mvc:annotation-driven/>浅析的相关文章

Spring MVC annotation configuration

1. Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns

Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

严重: StandardWrapper.Throwableorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested excepti

[Spring MVC] - Annotation验证

使用Spring MVC的Annotation验证可以直接对view model的简单数据验证,注意,这里是简单的,如果model的数据验证需要有一些比较复杂的业务逻辑性在里头,只是使用annotation做验证是比较难的. 以下是使用Spring MVC自带的annotation验证,加上自定义的一个@Tel的annotation验证例子,此例子具有: 1.支持多语言(国际化) 2.对默认数据先进行转化,比如int.date类型如果传入空值时,会抛异常,默认给定值 先看配置: 1.web.xm

asp.net MVC之AuthorizeAttribute浅析

AuthorizeAttribute是asp.net MVC的几大过滤器之一,俗称认证和授权过滤器,也就是判断登录与否,授权与否.当为某一个Controller或Action附加该特性时,没有登录或授权的账户是不能访问这些Controller或Action的. 在进入一个附加了Authorize特性的Controller或Action之前,首先执行的是AuthorizeAttribute类的OnAuthorization(AuthorizationContext filterContext)方法

Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestPar

Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable Pankaj July 4, 2014 Spring @RequestMapping is one of the most widely used Spring MVC annotation.org.springframework.web.bind.annotat

Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable--转载

原文地址: @RequestMapping is one of the most widely used Spring MVC annotation.org.springframework.web.bind.annotation.RequestMapping annotation is used to map web requests onto specific handler classes and/or handler methods. @RequestMapping can be appl

Domain Driven Design and Development In Practice--转载

原文地址:http://www.infoq.com/articles/ddd-in-practice Background Domain Driven Design (DDD) is about mapping business domain concepts into software artifacts. Most of the writings and articles on this topic have been based on Eric Evans' book "Domain Dr

Annotation Type @bean,@Import,@configuration使用--官方文档

@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean Indicates that a method produces a bean to be managed by the Spring container. Overview The names and semantics of the attributes to this annotation

Spring MVC Test -Controller

http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-configuration/ Writing unit tests for Spring MVC controllers has traditionally been both simple and problematic. Although it is pretty simple to write