spring 版本: 4.3.7 addFormatters(FormatterRegistry registry) 不生效

<!-- 此处与 @EnableWebmvc 冲突, 配置此处后 EnableWebmvc 中的配置无效 -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8"/>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
<value>text/plain;charset=utf-8</value>
<value>text/html;charset=UTF-8</value>
<value>text/json;charset=UTF-8</value>
<value>text/html;charset=ISO-8859-1</value>
<value>application/x-www-form-urlencoded;charset=UTF-8</value>
</list>
</property>
<property name="prettyPrint" value="false"></property>
<property name="objectMapper">
<bean class="com.we.core.web.view.JsonMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
@Configuration
@EnableWebMvc
public class WebAppConfig extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
super.addFormatters(registry); registry.addConverterFactory(new StrValueToEnumConverterFactory());
} }

暂时不清楚是 spring 设计如此 还是 bug 。

  • 解决方案 (建议根据基于现有配置修改)
  1. 使用 xml <mvc:annotation-driven>:

<!-- conversion-service="mvcConversionService" conversion-service 这个有两个 bean , 使用 mvcConversionService
(经过 debug 调试, 另一个是错误的)-->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"
conversion-service="mvcConversionService">
<!-- 省略 -->
</mvc:annotation-driven>
  1. 删掉 <mvc:annotation-driven>......</mvc:annotation-driven>, 使用纯 java 配置

最新文章

  1. 【repost】JavaScript 事件模型 事件处理机制
  2. TJI读书笔记10-复用类
  3. 让你快速搭建一个bootstrap页面
  4. LevelDB:一个快速轻量级的key-value存储库(译)
  5. arrowTip 提示
  6. android 传感器使用 Compass指南针的实现功能
  7. 代码编写规范说明书(c#.net与asp.net)
  8. JavaScript系列-----对象基于哈希存储(&lt;Key,Value&gt;之Key篇) (1)
  9. PTA題目的處理(三)
  10. python部署lvs
  11. vue-cli(vue脚手架) 简单使用
  12. MYSQL 创建数据库SQL
  13. lua 的元表与元方法
  14. python出现编码问题的原因及编码问题的解决
  15. java文件夹相关操作 演示样例代码
  16. Week2-作业1:阅读与博客
  17. input输入框用el对数字格式化
  18. 【Java面试题】36 List、Map、Set三个接口,存取元素时,各有什么特点?
  19. sql server 查询所有被锁表并批量解除
  20. /etc/skel 目录作用

热门文章

  1. odoo 为可编辑列表视图字段搜索添加查询过滤条件
  2. JZOJ 5843.B
  3. JZOJ 2020.02.25【NOIP提高组】模拟A 组
  4. Python_使用Python将一个文件夹下的多个文件夹中的图片复制到一个文件夹中
  5. Qt-FFmpeg开发-视频播放【软解码 + OpenGL显示RGB图像】(3)
  6. AirTest
  7. ascii编码常用字符的十进制对照表
  8. ucloud 签名算法
  9. python + pyqt 实现的你下载css背景图片的小工具(最终版)
  10. 使用 Fiddler Everywhere 进行抓包