spring mvc @Configuration addConverterFactory 无效问题
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 配置
spring mvc @Configuration addConverterFactory 无效问题的更多相关文章
- eclipse maven spring mvc el表达式无效
http://www.myexception.cn/javascript/2031310.html
- Unit Testing of Spring MVC Controllers: Configuration
Original Link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...
- 搭建spring mvc项目
在之前搭建maven项目这篇的基础上继续集成,引入spring mvc支持 一.添加jar包引用 修改pom.xml文件,加入:(其他关联的jar包maven会自动引用) <!-- 项目属性 - ...
- Spring MVC Test -Controller
http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers- ...
- Spring MVC Integration,Spring Security
http://docs.spring.io/spring-security/site/docs/4.2.0.RELEASE/reference/htmlsingle/#authorize-reque ...
- 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 ...
- Spring MVC Hello World Example(转)
Spring 3 You may interest at this Spring 3 MVC hello world example. In Spring MVC web application, i ...
- [转] Spring MVC 4.1.3 + MyBatis 零基础搭建Web开发框架
首先感谢一下润和软件,指引我走上了Spring MVC Web开发的道路. 下面进入正题 搭建开发环境: Netbeans8.0.2 + MySql5.6 + JDK1.7 + tomcat8.0.1 ...
- 基于Maven的Spring + Spring MVC + Mybatis的环境搭建
基于Maven的Spring + Spring MVC + Mybatis的环境搭建项目开发,先将环境先搭建起来.上次做了一个Spring + Spring MVC + Mybatis + Log4J ...
- Spring MVC源码分析(三):SpringMVC的HandlerMapping和HandlerAdapter的体系结构设计与实现
概述在我的上一篇文章:Spring源码分析(三):DispatcherServlet的设计与实现中提到,DispatcherServlet在接收到客户端请求时,会遍历DispatcherServlet ...
随机推荐
- JZOJ 3447.摘取作物
\(\text{Problem}\) 在一个矩阵里选数,每行最多选两个,每列最多选两个,最大会价值 \(n,m \le 30\) \(\text{Analysis}\) 对个这个限制如何实现? 跑费用 ...
- Vulhub 漏洞学习之:Fastjson
Vulhub 漏洞学习之:Fastjson 目录 Vulhub 漏洞学习之:Fastjson 0 背景知识 0.1 FastJson POC解析 0.1.1 基于rmi的利用方式 0.1.2 基于ld ...
- PostGIS之空间索引
1. 概述 PostGIS 是PostgreSQL数据库一个空间数据库扩展,它添加了对地理对象的支持,允许在 SQL 中运行空间查询 PostGIS官网:About PostGIS | PostGIS ...
- 基于Python的OpenGL 06 之摄像机
1. 引言 本文基于Python语言,描述OpenGL的摄像机 前置知识可参考: 基于Python的OpenGL 05 之坐标系统 - 当时明月在曾照彩云归 - 博客园 (cnblogs.com) 笔 ...
- “堆内存持续占用高 且 ygc回收效果不佳” 排查处理实践
作者:京东零售 王江波 说明:部分素材来源于网络,数据分析全为真实数据. 一. 问题背景 自建的两套工具,运行一段时间后均出现 内存占用高触发报警,频繁young gc且效果不佳.曾经尝试多次解决,因 ...
- gin 01
1.gin介绍: 2.gin的安装 go get -u github.com/gin-gonic/gin 3.gin的第一个helloWord package main import ( " ...
- 全国计算机二级python备考
选择题: https://www.itkaoshi.net/3476.html 操作题: https://www.bilibili.com/video/BV1Zj411f7ey?p=1 经典题讲解: ...
- ol序号并在序号加背景色
<style type="text/css"> .list {list-style-type: none;margin: 0;padding: 0 0 0 30px;} ...
- Create 1select+jdbc+jsp
<form action="UserServlet" method="get"> 查询条件:<input type="text&qu ...
- [C#]判断一个IP是否在某个IP段内
关于IP地址 IPv4地址是由4段0-255的数字组成的,例如:a.b.c.d(0≤a,b,c,d≤255),IPv4也叫32位地址,为什么是32位呢,因为把每一段转换成二进制后,它的取值范围就是00 ...