spring-web是web开发得力的框架,版本升级之后我们以前后台配置文件的MappingJacksonHttpMessageConverter
报错查看版本比较信息spring最后一版支持 MappingJacksonHttpMessageConverter 的是4.0.9
之后完全使用了MappingJackson2HttpMessageConverter 直接删除了MappingJacksonHttpMessageConverter导致我们程序报错
还有我们使用的jackson-mapper-asl也会启动报错.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
替换方法是将
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
换成
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.7</version>
</dependency><mvc:annotation-driven>
<mvc:message-converters>
<!--编码的配置-->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!--
Spring mvc 自动反序列化的配置类
spring3.x是org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
spring4.x是org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
-->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<!--NULL的处理 让其不出现在响应中 或者在类中使用注解 @JsonInclude(JsonInclude.Include.NON_NULL)-->
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion" value="NON_NULL"/>
</bean>
</property>
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>