spring mvc @Configuration addConverterFactory 无效问题
2024-10-20 20:40:11
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 。
- 解决方案 (建议根据基于现有配置修改)
- 使用 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>
- 删掉
<mvc:annotation-driven>......</mvc:annotation-driven>
, 使用纯 java 配置
最新文章
- 【repost】JavaScript 事件模型 事件处理机制
- TJI读书笔记10-复用类
- 让你快速搭建一个bootstrap页面
- LevelDB:一个快速轻量级的key-value存储库(译)
- arrowTip 提示
- android 传感器使用 Compass指南针的实现功能
- 代码编写规范说明书(c#.net与asp.net)
- JavaScript系列-----对象基于哈希存储(<;Key,Value>;之Key篇) (1)
- PTA題目的處理(三)
- python部署lvs
- vue-cli(vue脚手架) 简单使用
- MYSQL 创建数据库SQL
- lua 的元表与元方法
- python出现编码问题的原因及编码问题的解决
- java文件夹相关操作 演示样例代码
- Week2-作业1:阅读与博客
- input输入框用el对数字格式化
- 【Java面试题】36 List、Map、Set三个接口,存取元素时,各有什么特点?
- sql server 查询所有被锁表并批量解除
- /etc/skel 目录作用
热门文章
- odoo 为可编辑列表视图字段搜索添加查询过滤条件
- JZOJ 5843.B
- JZOJ 2020.02.25【NOIP提高组】模拟A 组
- Python_使用Python将一个文件夹下的多个文件夹中的图片复制到一个文件夹中
- Qt-FFmpeg开发-视频播放【软解码 + OpenGL显示RGB图像】(3)
- AirTest
- ascii编码常用字符的十进制对照表
- ucloud 签名算法
- python + pyqt 实现的你下载css背景图片的小工具(最终版)
- 使用 Fiddler Everywhere 进行抓包