美文网首页Spring
Spring mvc 报错java.lang.ClassNotF

Spring mvc 报错java.lang.ClassNotF

作者: Devid | 来源:发表于2017-02-24 10:59 被阅读785次

这个问题一般出现在使用Spring 4时,因为:

spring3.x是org.springframework.http.converter.json.MappingJacksonHttpMessageConverter

spring4.x是org.springframework.http.converter.json.MappingJackson2HttpMessageConverter

所以Spring3.x配置如下:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
    <property name="messageConverters">  
        <list>  
            <ref bean="jsonHttpMessageConverter" />  
        </list>  
    </property>  
</bean>  
  
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
    <property name="supportedMediaTypes">  
        <list>  
            <value>application/json;charset=UTF-8</value>  
        </list>  
    </property>  
</bean>  

Spring 4.x配置如下:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
    <property name="messageConverters">  
        <list>  
            <ref bean="jsonHttpMessageConverter" />  
        </list>  
    </property>  
</bean>  
  
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
    <property name="supportedMediaTypes">  
        <list>  
            <value>application/json;charset=UTF-8</value>  
        </list>  
    </property>  
</bean>  

相关文章

网友评论

    本文标题:Spring mvc 报错java.lang.ClassNotF

    本文链接:https://www.haomeiwen.com/subject/mbpqsttx.html