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 ...
随机推荐
- Python GDAL读取栅格数据并基于质量评估波段QA对指定数据加以筛选掩膜
本文介绍基于Python语言中gdal模块,对遥感影像数据进行栅格读取与计算,同时基于QA波段对像元加以筛选.掩膜的操作. 本文所要实现的需求具体为:现有自行计算的全球叶面积指数(LAI).t ...
- 3D数字孪生场景编辑器介绍
1.背景 数字孪生的建设流程涉及建模.美术.程序.仿真等多种人才的协同作业,人力要求高,实施成本高,建设周期长.如何让小型团队甚至一个人就可以完成数字孪生的开发,是数字孪生工具链要解决的重要问题.目前 ...
- 微信小程序之permission字段
最近查看我发布的小程序出了问题,没有显示天气,打开文件查看,出现如下提示 那么如何解决呢 在 app.json 里面增加 permission 属性配置然后在app.json中添加代码 整个app.j ...
- 数据结构和算法day1(Java)
1.什么是数据结构? 数据结构就是把数据元素按照一定的关系组织起来的集合,用来组织和存储数据. 1.2.数据结构的分类: 逻辑结构 和物理结构 逻辑结构: 集合结构(无关系).线性结构(一对一).树形 ...
- LeetCode-1601 最多可达成的换楼请求数目
来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests 题目 ...
- Apinto 网关 V0.11.1 版本发布,多协议互转,新增编码转换器,接入 Prometheus...
憋了那么久,Eolink 旗下 Apinto 开源网关再次更新啦~ 一起来看看是否有你期待的功能! 1.协议转换功能上线 之前发布的 Apinto v0.10.0 已经支持了多协议的基本功能,实现多协 ...
- 09 安装虚拟机:Ubuntu Server 20.04
09 安装虚拟机:Ubuntu Server 20.04 9.1 取得安装映像档 9.2 建立虚拟机客体 请至Proxmox VE管理界面点选右上方的[建立VM],来到建立虚拟机客体的引导程序.引导程 ...
- Vulnhub:ReconForce-01.1靶机
kali:192.168.111.111 靶机:192.168.111.200 信息收集 端口扫描 nmap -A -v -sV -T5 -p- --script=http-enum 192.168. ...
- 快速构建用户xlwings环境
一.安装python python-3.8.3-amd64.exe 二.准备文件requirements.txt 内容如下 安装失败需要切换国内镜像源 numpy==1.22.1 openpyxl== ...
- SpringBoot启动失败问题
SpringBoot启动失败问题 一.现象 pom.xml没有显示报错,也能查看到各种需要的依赖jar包,但在启动时显示 二.原因 网络不好导致maven导包失败或者导包不完整 三.解决办法 进入项目 ...