zoukankan      html  css  js  c++  java
  • <mvc:annotation-driven/>都做了那些事情

    mvc:annotation-driven是一种简写的配置方式,那么mvc:annotation-driven到底做了哪些工作呢?如何替换掉mvc:annotation-driven呢?

    <mvc:annotation- driven/>在初始化的时候会自动创建两个对 象,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 和 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter, 我们如果想不使用<mvc:annotation-driven/>这种简写方式,将其替换掉的话,就必须自己手动去配置这两个bean对 象。下面是这两个对象的配置方法,和详细的注视说明。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
    
        <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
            <property name="useDefaultSuffixPattern" value="false" />
            <property name="interceptors">
                <list>
                    <bean class="org.mspring.mlog.web.interceptor.RememberMeInterceptor" />
                    <bean class="org.mspring.mlog.web.interceptor.SettingInterceptor" />
                    <bean class="org.mspring.platform.web.query.interceptor.QueryParameterInterceptor" />
                </list>
            </property>
        </bean>
    
        <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
        <bean
            class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                <list>
                    <-- 这个converter是我自己定义的,是为了解决spring自带的StringHttpMessageConverter中文乱码问题的 -->
                    <bean class="org.mspring.platform.web.converter.StringHttpMessageConverter">
                        <constructor-arg value="UTF-8" />
                    </bean>
                    <!-- 这里可以根据自己的需要添加converter -->
                    <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
                    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
                    <!-- -->
                </list>
            </property>
            <property name="customArgumentResolvers">
                <list>
                    <bean class="org.mspring.platform.web.resolver.UrlVariableMethodArgumentResolver" />
                </list>
            </property>
    
            <property name="webBindingInitializer">
                <bean id="webBindingInitializer"
                    class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                    <property name="conversionService" ref="conversionService" />
                </bean>
            </property>
        </bean>
    
        <!-- 1, 注册ConversionService -->
        <bean id="conversionService"
            class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
            <property name="converters">
                <list>
                    <bean class="org.mspring.platform.web.converter.DateConverter">
                        <property name="pattern" value="yyyy-MM-dd HH:mm:ss" />
                    </bean>
                </list>
            </property>
            <property name="formatters">
                <list>
                    <bean class="org.mspring.mlog.web.formatter.factory.TagFormatAnnotationFormatterFactory"></bean>
                    <bean class="org.mspring.mlog.web.formatter.factory.EncodingFormatAnnotationFormatterFactory"></bean>
                </list>
            </property>
        </bean>
    
    </beans>
    View Code

    这样,我们就可以就成功的替换掉<mvc:annotation-driven />了。

  • 相关阅读:
    Linux文件目录结构详解
    Linux常用命令学习
    51Nod 1094 和为k的连续区间 | 水
    (转) jsp学习笔记
    Hadoop到底能做什么?怎么用hadoop?
    51Nod 1092 回文字符串 | 最长公共子序列变形
    51Nod 1067 Bash游戏 V2 | 博弈论 Bash
    51Nod 1062 序列中最大的数 | 简单DP
    51Nod 1050 循环数组最大子段和 | DP
    HDU 5643 King's Game | 约瑟夫环变形
  • 原文地址:https://www.cnblogs.com/shines77/p/3315445.html
Copyright © 2011-2022 走看看