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

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>
???????????????????????????
?????????????????????????? <property name="autodetectAnnotations" ><value>true</value></property>
?????????????????????????? <!--可以与xml互换的对象,需要使用XStream的注解,注解的使用方法请参XStream官网-->

?????????????????????????? <property name="annotatedClasses">
?????????????????????????????? <list>
?????????????????????????????????? <value>com.xxx.XxxxDTO</value>
?????????????????????????????? </list>
?????????????????????????? </property>
??????????????????????????
??? ??? ??? ??? ??????? </bean>
??? ??? ??? ??? ??? </constructor-arg>
??? ??? ??? ??? </bean>?
??? ??? ??? ??? <bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
??? ??? ??? ??? <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
??? ??? ??? ??? <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
??? ??? ??? ??? <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
??? ??? ??? ??? <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>

??????????????? <!--可以增加其他数据类型,请参考spring的API-->
??? ??? ??? </list>
??? ??? </proper