spring 解决冲突,配置拦截器与jackson转化支持

Posted 呆萌小码

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring 解决冲突,配置拦截器与jackson转化支持相关的知识,希望对你有一定的参考价值。

<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"
    default-lazy-init="true">

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/api/admin/**/*.jspx"/> 
        <bean id="frontAPIInterceptor" class="com.yssjcms.cms.web.FrontAPIInterceptor"/>
    </mvc:interceptor>
    <mvc:interceptor>
        <mvc:mapping path="/**"/> 
        <mvc:exclude-mapping path="/api/admin/**/*.jspx"/>
        <bean id="frontContextInterceptor" class="com.yssjcms.cms.web.FrontContextInterceptor"/>
    </mvc:interceptor>
    <mvc:interceptor>
        <mvc:mapping path="/**"/> 
        <mvc:exclude-mapping path="/api/admin/**/*.jspx"/>
        <bean id="frontLocaleInterceptor" class="com.yssjcms.cms.web.FrontLocaleInterceptor"/>
    </mvc:interceptor>
</mvc:interceptors>
<mvc:annotation-driven>
    <mvc:message-converters register-defaults="false"> <!-- 不使用默认配置 -->
        <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
        <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
        <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
        <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
            <property name="supportedMediaTypes"> 
                <list>
                    <value>text/html;charset=UTF-8</value>
                    <value>application/json;charset=UTF-8</value>
                </list>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

    <context:annotation-config/>
</beans>

 

以上是关于spring 解决冲突,配置拦截器与jackson转化支持的主要内容,如果未能解决你的问题,请参考以下文章

spring3.1.1正常的在spring 4.1.2 配置 jackson 返回406 如何解决

Spring MVC Jackson 消息转换器:“冲突的设置器定义”

拦截器配置类使用继承写法导致jackson的全局配置失效

一文详解JackSon配置信息

SpringBoot自定义拦截器和跨域配置冲突

xfire冲突问题解决(maven配置)