日期:2014-05-16  浏览次数:20490 次

Spring3 MVC Restful 多请求类型(json,xml,k-v),多视图配置(Json,Xml,JSP,Freemarker,Volacity等)
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  
    <context:component-scan base-package="com.xxx." />
    <aop:aspectj-autoproxy proxy-target-class="true" />
    <context:annotation-config />
    <import resource="classes/DataSource.xml"/>
    <import resource="classes/applicationContext.xml"/>
    <mvc:interceptors>
        <bean class="com.globeway.web.servlet.intercept.JsonGetInterceptor" />
    </mvc:interceptors>

    <bean id="defaultAnnotationHandlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" ></bean>
   
    <!-- 配置多请求数据类型,如json xml-->
    <bean id="annotationMethodHandlerAdapter"  class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
        <property name="messageConverters">
            <list>
                <!-- 解析json请求数据,将json转换为java对象-->
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
                <!-- 解析xml请求数据,将xml转换为java对象-->
                <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                    <constructor-arg>
                        <bean class="org.springframework.oxm.xstream.XStreamMarshaller">
                           <property name="streamDriver" >
                               <bean class="com.thoughtworks.xstream.io.xml.DomDriver"/>
                           </property>                 &nbs