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 1078. 【GDOI2006】The Kth Element
\(\text{Problem}\) 给定一个整数序列 \(a[1..N]\),定义 \(sum[i][j]=a[i]+a[i+1]+...+a[j]\),将所有的 \(sum[i][j]\) 从小到 ...
- JZOJ 4319. 【NOIP2015模拟11.5】Lucas的数列
题目 思路 暴力很好打,我们显然可以先把关于 \(k\) 的式子拆开 先二项式展开,然后把外面的 \(m\) 乘进去,把 \(p\) 的分母 \(m\) 消去 \(K = (\sum_{i=1}^m ...
- [COCI2010-2011#6] STEP
题目大意 维护一个 \(01\) 序列最长的连续相邻两个数不同的子序列的长度 解析 很裸的线段树题... 要维护的信息很多 区间长度 区间最左端点 区间最右端点 区间最长前缀 区间最长后缀 区间最终的 ...
- HACLABS: NO_NAME
HACLABS: NO_NAME 目录 HACLABS: NO_NAME 1 信息收集 1.1 端口扫描 1.2 后台目录扫描 1.2.1 目录分析 2 命令注入利用 2.1 尝试反弹Shell 2. ...
- CSS 定位position
.link span { position: absolute; top: 0; left: 50%; transform: translateX(-50%); }
- JS的有关递归的知识点(数据无限级联的实现)
所用测试数据: 1 const data = [ 2 { 3 "area_id": 5, 4 "name": "广东省", 5 " ...
- redis-centOS系统的环境安装
近期要简单汇总一下Redis常用的方法,依赖环境配置,在网上看到一篇比较好的Redis环境搭建博客,分享给大家.因新版本Redis已不支持windowns,环境安装以centOS系统为主. 参考博客地 ...
- Word11 工程学院讲师论文office真题
1.根据题目一的要求,打开素材文件,点击[文件]-[另存为],选择[当前文件夹],命名为Word. 2.根据题目二的要求,根据提供的参考样式,打开Word的文档,在[布局]里点击[页面设置]的右下角, ...
- 【C学习笔记】day5-1 完成猜数字游戏
#include <stdio.h> #include <stdlib.h> int main() { int s = 0; srand((unsigned)time(NULL ...
- 【C学习笔记】day3-3 编写程序数一下 1到 100 的所有整数中出现多少个数字9
#include <stdio.h> int main() { int cou=0; for (int i = 1; i <= 100; i++) { if (i % 10 == 9 ...