新框架总是不断的出现,已经有的中间件也在不断更新,最近用springmvc4.3搭建开发环境说下配置文件springmvc配置文件遇到的坑 配置文件头部的声明也要随着版本号变更这个没什么说的。 重要的部分是如下 4.3主要配置信息
版本4.0: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
版本3.0:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
4.3中不再存在文件 MappingJacksonHttpMessageConverter annotation.AnnotationMethodHandlerAdapter 被替换为 method.annotation.RequestMappingHandlerAdapter
<bean id="mappingJacksonHttpMessageConverter" 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> <property name="objectMapper"> <bean class="com.fasterxml.jackson.databind.ObjectMapper"> <!-- <property name="serializationInclusion"> <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value> </property> --> <!-- 为null字段时不显示 --> <property name="serializationInclusion"><!-- 数据是否空值处理: ALWAYS, NON_NULL, NON_DEFAULT, NON_EMPTY --> <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value> </property> <!-- 处理responseBody 里面日期类型 --> <property name="dateFormat"> <bean class="java.text.SimpleDateFormat"> <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" /> </bean> </property> <!-- 时区指定 --> <property name="timeZone" value="GMT+8" /> </bean> </property> </bean> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 --> </list> </property> </bean>