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 配置

spring mvc @Configuration addConverterFactory 无效问题的更多相关文章

  1. eclipse maven spring mvc el表达式无效

    http://www.myexception.cn/javascript/2031310.html

  2. Unit Testing of Spring MVC Controllers: Configuration

    Original Link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...

  3. 搭建spring mvc项目

    在之前搭建maven项目这篇的基础上继续集成,引入spring mvc支持 一.添加jar包引用 修改pom.xml文件,加入:(其他关联的jar包maven会自动引用) <!-- 项目属性 - ...

  4. Spring MVC Test -Controller

    http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers- ...

  5. Spring MVC Integration,Spring Security

     http://docs.spring.io/spring-security/site/docs/4.2.0.RELEASE/reference/htmlsingle/#authorize-reque ...

  6. Step-by-Step XML Free Spring MVC 3 Configuration--reference

    The release of Spring 2.5 reduce the burden of XML by introduction annotation based configuration, b ...

  7. Spring MVC Hello World Example(转)

    Spring 3 You may interest at this Spring 3 MVC hello world example. In Spring MVC web application, i ...

  8. [转] Spring MVC 4.1.3 + MyBatis 零基础搭建Web开发框架

    首先感谢一下润和软件,指引我走上了Spring MVC Web开发的道路. 下面进入正题 搭建开发环境: Netbeans8.0.2 + MySql5.6 + JDK1.7 + tomcat8.0.1 ...

  9. 基于Maven的Spring + Spring MVC + Mybatis的环境搭建

    基于Maven的Spring + Spring MVC + Mybatis的环境搭建项目开发,先将环境先搭建起来.上次做了一个Spring + Spring MVC + Mybatis + Log4J ...

  10. Spring MVC源码分析(三):SpringMVC的HandlerMapping和HandlerAdapter的体系结构设计与实现

    概述在我的上一篇文章:Spring源码分析(三):DispatcherServlet的设计与实现中提到,DispatcherServlet在接收到客户端请求时,会遍历DispatcherServlet ...

随机推荐

  1. 安装KaLi操作系统并优化

    安装KaLi操作系统并优化 1. 开启ROOT登录 安装操作系统跳过,下面直接做系统优化,方便以后使用! 有两种方法,可以实现开机以root身份登录kali系统. 第一种方法如下: 在终端下输入所需命 ...

  2. JZOJ 3469. 【NOIP2013模拟联考7】数列(sequence)

    \(\text{Solution}\) 明显的 \(\text{K-D Tree}\) 基操题 提前给出了数列,那么考虑提前建好树,省去重构 但还是要开 \(O\) \(\text{Code}\) # ...

  3. filter 和 map 的异同

    filter是满足条件的留下,是对原数组的过滤:map则是对原数组的加工,映射成一一映射的新数组 filter() Filter() 创建一个新数组,新数组中返回的值为经过检查指定数组中满足条件的所有 ...

  4. Cesium之影像底图加载

    1. 引言 Cesium是一款三维地球和地图可视化开源JavaScript库,使用WebGL来进行硬件加速图形,使用时不需要任何插件支持,基于Apache2.0许可的开源程序,可以免费用于商业和非商业 ...

  5. 脚本之美│VBS 入门交互实战

    目录 什么是 VBS 第一个 VBS 脚本 msgbox 语法 中文乱码 弹窗交互功能 表白恶搞 什么是 VBS VBS 是一种 Windows 脚本语言,全称是 Microsoft Visual B ...

  6. Sptring cloud Alibaba Sentinel 实现熔断与限流

    随着微服务的流行,服务和服务之间的稳定性变得越来越重要. Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度保护服务的稳定性. 作用: 服务雪崩 服务降级 服务熔断 服务限 ...

  7. (unsigned)short溢出后隐式转换为int

    同学被面试官问到一个细节中的细节,虽然个人觉得意义不大,但还是好奇并在和同学一起实验后搞清楚了,记录一下 如下: int main() { unsigned short a = 65535, b = ...

  8. 安装pytorch报错 ERROR: Could not install packages due to an OSError: [Errno 28] No space left on device

    windos安装,报错如下 看了不少回答,大概是缓存和内存满了 我的C盘只给了70G,然后意外发现只剩下3G多了,先用系统自带的清理工具清理了一下,然后腾讯电脑管家"工具箱"中的& ...

  9. Windows 下安装 Bun:像 Node 或 Deno 一样的现代 JavaScript 运行时

    背景 最近前端工具链又火了一个项目 Bun,可以说内卷非常严重.Bun 是一个新的 JavaScript 运行时,内置了打包器.转译器.任务运行器和 npm 客户端. Bun 是像 Node 或 De ...

  10. 新的学习历程-python2 print

    1 print('hello world!') 2 print('hello','world!') #逗号自动添加默认的分隔符:空格 3 print('hello'+'world!') #加号表示字符 ...